In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Create a mirror using Dockerfile
General Dockerfile is divided into four parts: basic image information, maintainer information, mirror operation instructions and instructions when the container starts.
1. Instruction description
Instruction description FROM specifies the basic image of the created image MAINTAINER specifies maintainer information RUN run command CMD specifies the command LABEL that is executed by default when starting the container EXPOSE states the port that the service listens in the image ENV specifies the environment variable ADD copies the content under the specified path to the container, it can be URL; if it is a tar file, it will be automatically decompressed to the path. COPY copies the content under the specified path to the path in the container It is generally recommended to use COPY instead of ADDENTRYPOINT to specify the default entry for the image, VOLUME to create the data volume mount point, USER to specify the user name when running the container or UIDWORKDIR configuration working directory ARG to specify parameters (such as version number information, etc.) ONBUILD configuration when the created image is used as the base image for other images Create operation instruction STOPSIGNAL container exit signal value HEALTHCHECK how to perform a health check SHELL specifies the default shell type when using shell
two。 Create a mirror
After writing the Dockerfile, execute the docker build command to create the mirror.
The basic format is docker build [option] content path
If you want to develop label information to generate an image, you can use the-t option.
Docker build-t myfirstimage. /
3. Use the .dockerkeeper file
Use the .dockerboards file (add a matching pattern per line) to have Docker ignore the matching pattern path
# comment
/ temp
/ / temp
Tmp?
~
Best practic
Simplify the use of mirrors: try to make the use of each mirror more centralized and single, so as to avoid constructing large and complex images with multiple functions
Select a suitable basic image: too large a basic image will result in a bloated image. A smaller debian image is generally recommended.
Provide clear enough command comments and maintainer information: Dockerfile is also a kind of code that needs to be considered for subsequent extensions and use by others
Correct use of version numbers: using clear version number information, such as 1.0Jing 2.0 instead of latest, will avoid tragedies that may be caused by inconsistent content
Reduce the number of mirror layers: if you want to generate as few mirror layers as possible, merge instructions as much as possible, for example, multiple RUN instructions can be merged into one
Delete temporary and cache files in a timely manner: especially after the execution of the apt-get directive, some installation packages will be cached under / var/cache/apt
Improve generation speed: such as using cache properly, reducing the number of files in the content directory, or using .dockerkeeper files to specify, etc.
Adjust the reasonable order of instructions: when the cache is turned on, the instructions with the same contents should be put in front as far as possible, so that they can be reused as much as possible.
Reduce interference from external sources: if you do bring in data from outside, you need to specify a persistent address with version information so that others can repeat without error. ****
Summary:
(❐❐✧) if you are ugly, you should read more books.
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.