This is the fourth day of my participation in the August More text Challenge. For details, see:August is more challenging

1. WriteDockerfilefile

Create a new Dockerfile file in the project root directory

vi Dockerfile
Copy the code

FROM Java :8 ENV WORK_PATH /usr/local/open-web WORKDIR $WORK_PATH COPY./target/web-1.0.0.jar $WORK_PATH/web-1.0.0.jar ENTRYPOINT [" Java ", "- the jar", "/ usr/local/open web/web - 1.0.0. Jar"]Copy the code

2. Run the mirror building command

Docker build -f./Dockerfile -t open-web:1.0.0.Copy the code

3. Run

Docker run -p 5001:5001 --name open-web -d open-web:1.0.0 docker run -p 5001:5001 --name open-web -d open-web:1.0.0Copy the code

4. Basic Dockerfile commands

4.1 FROM

Base Mirror That the current new mirror is based on

4.2 RUN

Commands that need to be run when the image is built

4.3 EXPOSE

Port that the current container is exposed to

4.3 WORKDIR

Specifies that after the container is created, the terminal is logged into the working directory by default, a foothold

4.4 ENV

Used to set environment variables during the mirror build process

4.5 ADD

Copy the files in the host directory into an image. The ADD command automatically processes the URL and decompresses the tar package

4.6 COPY

Similar to ADD, copy files and directories to an image. Copies files/directories from < source path > in the build context directory to the < target path > location in the mirror at the new level

4.7 VOLUME

Container data volumes for data preservation and persistence

4.8 CMD

Specifies the command to run when a container is started. There can be multiple CMD commands in a Dockerfile, but only the last one will take effect. CMD will be replaced by arguments after docker run

4.9 ENTRYPOINT

Specify a command to run when the container starts. The purpose of ENTRYPOINT, like CMD, is to specify the container launcher and its parameters

5. Small case

Build your own Tomcat image

FROM ubuntu ADD jdk-8u221-linux-x64.tar.gz /usr/local/apache-tomcat-8.5.45.tar. gz /usr/local/env MYPATH /usr/local WORKDIR $MYPATH ENV JAVA_HOME /usr/local/jdk1.8.0_221 ENV JRE_HOME $JAVA_HOME/jre ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH ENV PATH $JAVA_HOME/bin:$JRE_HOME/bin:$PATH RUN echo export JAVA_HOME=$JAVA_HOME>>~/.bashrc RUN echo export JRE_HOME=$JRE_HOME>>~/.bashrc RUN echo export CLASSPATH=$CLASSPATH>>~/.bashrc RUN echo export PATH=$PATH>>~/.bashrc RUN /bin/bash -c "source ~/.bashrc" EXPOSE 8080 CMD /usr/local/apache-tomcat-8.5.45/bin/startup.sh && tail -f /usr/local/apache-tomcat-8.5.45/logs/catalina.outCopy the code