In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
We can learn from the previous article that the customization of the image is actually customizing the configuration, files and other information added by each layer, but after all, the command is only a command, and each customization has to repeat this command, and it is not intuitive enough. If we can write the commands for modifying, installing, building and operating each layer into a script, use this script to build and customize the image Then all these problems can be solved? Yes, this script is what we call Dockerfile.
Introduction
Dockerfile is a text file that contains Instruction, each of which builds a layer, so the content of each instruction is to describe how the layer should be built.
Here we take the custom tomcat image as an example, this time we use Dockerfile to customize it. In a blank directory, create a text file and name it Dockerfile:
[root@192 mydocker] # cat DockerfileFROM jdk:latestADD apache-tomcat-9.0.27.tar.gz / data/softRUN rm-rf apache-tomcat-9.0.27.tar.gzWORKDIR / data/soft/ENTRYPOINT / data/soft/apache-tomcat-9.0.27/bin/startup.sh & & tail-f / dev/null [root@192 mydocker] # docker build-t tomcat:test .Sending build context to Docker daemon 500.2MBStep 1 FROM jdk:latest-> d8252cab0866Step 2max 5 : ADD apache-tomcat-9.0.27.tar.gz / data/soft-- > d0f4873733b8Step 3Running in 90dfd42c6134Removing intermediate container 90dfd42c6134 5: RUN rm-rf apache-tomcat-9.0.27.tar.gz-- > Running in 7d54b3ccd7caRemoving intermediate container 7d54b3ccd7ca-- > 1f07735cd7daStep 4 WORKDIR 5: WORKDIR / data/soft/-- > Running in 90dfd42c6134Removing intermediate container 90dfd42c6134-- > 5704cc83ebb3Step 5 data/soft/apache-tomcat-9.0.27/bin/startup.sh 5: ENTRYPOINT / data/soft/apache-tomcat-9.0.27/bin/startup.sh & & tail-f / dev/null -> Running in 5dd6eef5777eRemoving intermediate container 5dd6eef5777e-> d97a77aa1533Successfully built d97a77aa1533Successfully tagged tomcat:test [root@192 mydocker] # docker run-- name webserver-d-p 8080 name webserver-d-p 8080 tomcat:test / bin/bashe13e5b4d7807b5dbeec0eb55192602ed60cb289b95d82a455cdb340581aba150 [root@192 mydocker] # netstat-lntpActive Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 00 0.0.0.0 22 0.0.0. 0LISTEN 1093/sshd * LISTEN 1093/sshdtcp6 0 0: 8080: * LISTEN 48659/docker-proxytcp6 0 0: 22: * LISTEN 1093/sshd is accessed through the browser
Common instruction
Pay attention to the problem
The use of COPY ADD will design the problem of permissions. How to solve the problems of permissions?
You can use COPY-chown= or ADD-chown= to solve the problem
In the process of use, such as ADD uses the .tar.gz automatic decompression function, after the execution of build, the permissions in the package will not change. Then the COPY direct use right is directly changed to root.
The use of USER and which uses are affected
Affect the execution identity of the subsequent RUN CMD ENTRYPOINT commands, note that the COPY commands are not obeyed
The use of WORKDIR
Switch directories
An example
RUN cd / test
RUN echo "test" > test.txt
Is there / test/test.txt in the last image? A: NO
Explanation: there is a concept of layers in docker. Each command generates a layer, and each layer is a separate space. So on the second RUN, the working directory does not change to / test. Finally, a picture is used to explain the meaning of common instructions ^-^.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.