2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
1. Docker's packaging command isdocker build
。
It is used to package and build Docker images.docker build
The basic steps of the command:
Create a Dockerfile in the root directory of the project, which describes how to build a Docker image. Dockerfile is a text file that can contain a series of instructions and configuration items.
Execute the following command to build the image:
docker build -t <镜像名称> <Dockerfile所在目录路径>
in,-t
The parameter is used to specify a name for the image.<镜像名称>
is the name you want to give to the image.<Dockerfile所在目录路径>
is the path to the directory containing the Dockerfile.
Docker will build the image according to the instructions and configuration items in the Dockerfile. This process may take some time because it will download the required dependencies and execute the specified commands.
After the build is complete, you can usedocker images
command to see a list of all images. You should be able to find the image you just built in the list.
usedocker build
The command can quickly and automatically package and build Docker images, thus simplifying the application deployment process.
2. To package app.jar into a Docker image, you need to perform the following steps:
FROM openjdk:8-jdk-alpine
COPY app.jar /app.jar
CMD ["java", "-jar", "/app.jar"]
This Dockerfile uses OpenJDK 8 as the base image and copies app.jar to the root directory of the image. Then, the CMD instruction is executed when the container starts to run app.jar.
docker build -t app-image:latest .
This command will use the Dockerfile in the current directory to build an image called app-image with the image tag latest.
docker images
All images will be listed, and the app-image image just built can be found.
docker run -d -p 8080:8080 app-image
This command will run the app-image image in the background and map port 8080 in the container to port 8080 on the host. You can modify the port number according to the actual situation.
Now, app.jar has been successfully packaged into the Docker image, and you can start the application by running the image.