DockerFile file
Note: Mode 1 is the Docker File file that I used when I built the Docker image in SpringBook, which can be modified by myself.
1. Building a SpringBook Project Mirror Based on the Existing JDK Mirror
#Setting up JDK image FROM openjdk:8-jdk-slim VOLUME /tmp MAINTAINER sunhui #timezone RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN echo 'Asia/Shanghai' >/etc/timezone RUN echo $JAVA_OPTS ADD task-0.0.1-SNAPSHOT.jar app.jar RUN bash -c 'touch /app.jar' ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
2. Mirror based on ubuntu ($app is a placeholder here, instead of jar for your spring boot project)
FROM ubuntu:16.04 MAINTAINER sunhui ADD jdk-8u151-linux-x64.tar.gz /usr/local/jdk8 ENV JAVA_HOME /usr/local/jdk8/jdk1.8.0_151 ENV JRE_HOME $JAVA_HOME/jre ENV CLASSPATH :$JAVA_HOME/lib:$JRE_HOME/lib ENV PATH $PATH:$JAVA_HOME/bin ARG appADD $app app.jar ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
Docker Order and Interpretation
- FROM: Specify the base image of the created image. If it is not available locally, it will be downloaded from the official library.
- MAINTAINER: Author Information
- RUN: Run the specified command. The key point of creating a mirror is the behavior of each RUN, which is the same as the process of creating a mirror manually: create a new layer, execute these commands on it, submit the modification of this layer after execution, and form a new mirror. The above six RUN statements create six layers of mirrors, resulting in very bulky, very many layers of mirrors. So when there are more commands, use newline and & & connector to connect commands. Use as few RUN statements as possible. It can be written as follows: RUN apt-get update&apt-get install-y openssh-server...
- CMD: Specify the default commands to be executed when the container starts. Each Dockerfile can only have one CMD command. Docker is either a virtual machine or a container is a process. Since it is a process, you need to specify the program and parameters to run when you start the container. The CMD instruction is used to specify the default startup command for the container main process.
- EXPOSE: Declares the ports that the service in the mirror listens on
- ADD/COPY: Copy files
- ENTRYPOINT: Specifies the default entry command for the mirror. The command is executed as the root command at container startup, and all incoming values are taken as parameters of the command.
- ENV: Setting environment variables, whether it's later instructions, such as RUN, or runtime applications, can directly use the environment variables defined here.
- ARG: Specify some parameters (such as version number) to be used in the image and pass in in the format --- build-arg < Varname >= < value > when executing the docker build command.
- WORKDIR: Specify a working directory
3. Using Docker command to build SpringBook image in Linux
Preparations: First install the Docker container in the Linux system and start it, then put the Docker File files and SpringBook jar packages in the same directory, remember not to put them in the root directory (go through the pit), enter the directory to build the image.
1. Building Mirror Command: docker build-t Mirror Name: Version Number.
Example: There is a point at the end, which refers to the current directory. Never drop it!
[root@izuf60j0xye9c3vxjqujjiz local]# docker build -t task:xpv2.0 .
2. View Mirror Command: docker images
[root@izuf60j0xye9c3vxjqujjiz local]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE task xpv2.0 ec7ca41b419b 24 hours ago 378 MB ccr.ccs.tencentyun.com/linshang/task xpv1.1 d1211f22147e 25 hours ago 378 MB task-svc v1.1 d1211f22147e 25 hours ago 378 MB ccr.ccs.tencentyun.com/linshang/oauth test1.1 af93de61ae81 7 days ago 784 MB docker.io/openjdk 8-jdk-slim e95346262d2e 2 weeks ago 284 MB docker.io/openjdk 12.0.1-jdk-oraclelinux7 e92ef2c3a3dd 6 weeks ago 470 MB docker.io/rabbitmq 3-management df6f26ea3e53 3 months ago 213 MB docker.io/tomcat latest 5a069ba3df4d 3 months ago 465 MB docker.io/redis latest a55fbf438dfd 4 months ago 95 MB docker.io/mysql 5.5 4ee01d11a48b 4 months ago 205 MB docker.io/mysql latest 7bb2586065cd 4 months ago 477 MB docker.io/java 8 d23bdf5b1b1b 2 years ago 643 MB
3. Copy a modified label for Tencent Cloud
[root@izuf60j0xye9c3vxjqujjiz local]# sudo docker tag 6dba9e8c6c6a ccr.ccs.tencentyun.com/linshang/card:test2.0
4. Upload to Tencent Cloud Docker Container, login first, then push
[root@izuf60j0xye9c3vxjqujjiz local]# sudo docker login --username = user name ccr.ccs.tencentyun.com
[root@izuf60j0xye9c3vxjqujjiz local]# sudo docker push ccr.ccs.tencentyun.com/linshang/card:test2.0