idea uses docker to generate images (package images, import images, export images)

1: First download and install dockerdesktop, after the installation is successful

2: Execute docker -v in cmd to check the installed docker version

C:\Users\dell>docker -v
Docker version 24.0.5, build ced0996

3: You need to start the dockerdesktop application to start docker. Later, the idea needs to select Docker for windows to link the docker environment to generate the image.

Insert image description here

4: Install the docker plug-in in idea

Insert image description here

5: Create a Dockerfile file under the project (same directory as pom.xml)

Insert image description here

5-1:Dockerfile file content

#FROM openjdk:8-alpine
FROM anapsix/alpine-java:8_server-jre_unlimited


#对时作用
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

#目录是终端默认在此目录下
WORKDIR /test

EXPOSE 8088
#如果是到文件夹后面必须加上“/”,不然会找不到文件,./代表当前目录即是/test目录
COPY ./target/poi.jar ./app/

#poi.jar包就会在根目录/test/app/poi.jar下
CMD java -jar ./app/poi.jar

6: The green double arrow in the FROM location of the Dockerfile file to configure the link docker service

Insert image description here
Insert image description here

When selecting docker for windows, connection successful will appear, indicating that the connection to the local dockerdesktop application is successful.

Insert image description here

7: Build the image. When you see arrow 4 in the figure below, it means the image is built successfully ( note: sometimes the build is unsuccessful, you need to stop the docker connection service first, and then start it again )

Insert image description here
Insert image description here

Note: Pay attention to the server for database and redis installation. If it is a host installation, you need to specify the host IP address as follows

Insert image description here

Select images in the dockerdesktop application to see the built image.

Insert image description here

Start the image to become a container (1-Start, 2-Container naming, 3-It is the access port, 4-There can be multiple paths for the host and container to be mounted)

Insert image description here

You can see all the information of the container, operate the container terminal command and view various configuration information, start, stop, delete the container, etc.

Insert image description here

8: Export in windows and view the image through docker images command in cmd

  • Use docker save -o poiOne.tar image id ( when the exported image is moved to Linux and imported, REPOSITORY and TAG may be NONE)

  • Use docker save -o poiTwo.tar Image name: TAG ( the exported image is moved to Linux and imported without REPOSITORY and TAG is NONE)

C:\Users\dell>docker images
REPOSITORY            TAG                      IMAGE ID       CREATED         SIZE
poi                   1.0                      9ae198d48a31   4 minutes ago   175MB
anapsix/alpine-java   8_server-jre_unlimited   49d744fbb526   4 years ago     126MB

C:\Users\dell>docker save -o poiOne.tar 9ae198d48a31

C:\Users\dell>docker save -o poiTwo.tar poi:1.0

C:\Users\dell>

9: The command to import the image in linux or windows is

docker load -i poi.tar

Guess you like

Origin blog.csdn.net/qq_19891197/article/details/132384052