此内容没有您所选择的语言版本。
Chapter 2. Creating a custom container image
You can create a container image from your Quarkus application using one of the following methods:
- Creating a container manually
- Creating a container using the OpenShift Docker build
Compiling a Quarkus application to a native executable consumes a lot of memory during analysis and optimization. You can limit the amount of memory used during native compilation by setting the quarkus.native.native-image-xmx configuration property. Setting low memory limits might increase the build time.
2.1. Creating a container manually 复制链接链接已复制到粘贴板!
This section shows you how to manually create a container image with your application for Linux X86_64. When you produce a native image using the Quarkus Native container it creates an executable that targets the Linux X86_64 operating system. If your host operating system is different from this, you will not be able to run the binary directly and you will need to create a container manually.
Your Quarkus Getting Started project includes a Dockerfile.native in the src/main/docker directory with the following content:
The Dockerfiles use UBI as a base image. This base image was designed to work in containers. The Dockerfiles use the minimal version of the base image to reduce the size of the produced image.
Procedure
Build a native Linux executable using one of the following methods:
Build a native executable with Docker:
./mvnw package -Pnative -Dquarkus.native.container-build=true
./mvnw package -Pnative -Dquarkus.native.container-build=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Build a native executable with Podman:
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Build the container image using one of the following methods:
Build the container image with Docker:
docker build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/getting-started .
docker build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/getting-started .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build the container image with Podman
podman build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/getting-started .
podman build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/getting-started .Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Run the container:
Run the container with Docker:
docker run -i --rm -p 8080:8080 quarkus-quickstart/getting-started
docker run -i --rm -p 8080:8080 quarkus-quickstart/getting-startedCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the container with Podman:
podman run -i --rm -p 8080:8080 quarkus-quickstart/getting-started
podman run -i --rm -p 8080:8080 quarkus-quickstart/getting-startedCopy to Clipboard Copied! Toggle word wrap Toggle overflow
For information about deploying Quarkus Maven applications on Red Hat OpenShift Container Platform, see Deploying your Quarkus applications on Red Hat OpenShift Container Platform.
You can create a container image for your Quarkus application using the OpenShift Docker build strategy. This strategy creates a container using a build configuration in the cluster.
Prerequisites
- You have access to a Red Hat OpenShift Container Platform cluster and the latest version of the OpenShift CLI (oc) is installed. For information about installing oc, see the "Installing the CLI" section of the Installing and configuring OpenShift Container Platform clusters guide.
- A URL for the OpenShift API endpoint.
Procedure
Log in to the OpenShift CLI:
oc login -u <username_url>
oc login -u <username_url>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a new project in OpenShift:
oc new-project <project_name>
oc new-project <project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a build config based on the
src/main/docker/Dockerfile.nativefile:cat src/main/docker/Dockerfile.native | oc new-build --name <build_name> --strategy=docker --dockerfile -
cat src/main/docker/Dockerfile.native | oc new-build --name <build_name> --strategy=docker --dockerfile -Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build the project:
oc start-build <build_name> --from-dir .
oc start-build <build_name> --from-dir .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the project to OpenShift:
oc new-app <build_name>
oc new-app <build_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow