In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Before we begin
Previously, I pushed an article on the next-door project (official account goes out and turns left to Nginx). Nginx cache server (outside) Custom Docker Image We add the ngx_cache_purge module to the custom Nginx image to avoid the tedious step of installing the ngx_cache_purge module again after creating the container.
Use an example of the Java project today to show you how to create a custom Java image using Dockerfile, as well as some instructions commonly used in Dockerfile.
Environment description container image: openjdk:8-jre container system: debian 8 (jessie) Docker host: Ubuntu Server 16.04CI tool: Jenkins & Maven project program: compiled executable jar package operation steps to prepare the Dockerfile file cat bms/Dockerfile# bmsFROM openjdk:8-jreMAINTAINER dongnan# aptCOPY conf/sources.list / etc/apt/sources.listRUN apt-get update & apt-get install-y\ wkhtmltopdf xvfb\ & & apt-get clean & & rm-r / var/lib/apt/lists/*# envENV TZ=Asia/Shanghai\ LANG=C.UTF-8# packageCOPY src/bms.jar / root/bms.jar# workdirWORKDIR / root/# statement PortEXPOSE 808 cmdCMD ["java" "- jar", "/ root/bms.jar"] build an image
The daemon reads the Dockerfile file and executes it in the order of the instructions in the file. When building an image, it will be built layer by layer, and the former layer is the foundation of the latter layer. After each layer is built, there will be no change, and any changes on the latter layer will only occur in your own layer. Docker build-t bms:0.0.1 .Sending build context to Docker daemon 2.048 mb# omitted.... Successfully built cd34135ed904
Note: there is one last docker build command. Represents the current directory, and Dockerfile is in the current directory, in the specified context path.
Verify the mirror image
Try to use this image to create a container. If the container is running properly, the construction is successful. Docker run-- name test-tid bms:0.0.1
The same is true of mirroring using a hierarchical storage container, where each container runs with a mirror as the basic layer, creating a storage layer for the current container.
After the container is running, the files in the container are modified, that is, the storage layer of the container is changed, and the specific changes are seen through the docker diff command.
Docker container diff testC / root # C change A / root/logs # An add A / root/logs/bms.logC / tmpA / tmp/tomcat-docbase.1383372449962167136.9290 command to help docker build-- help
Dockerfile common instructions
Each instruction in Dockerfile creates a layer, and the above example creates a nine-layer image.
FROM: used to specify the base image, a valid Dockerfile must use FROM as the first instruction. MAINTAINER: used to set author information. RUN: is used to execute commands and submit the results to the current mirror layer. ENV: set the environment variable, whether it is subsequent instructions or runtime containers, you can use this environment variable directly. COPY: copy the files / directories from the build context directory to the location in the image of the new layer. ADD: the function is basically the same as the `COPY` instruction. However, some functions have been added to COPY, for example, ADD will do automatic decompression. WORKDIR: used to specify a working directory (* * current directory * *). If it does not exist, it will help you set up a directory. EXPOSE: is to declare that the runtime container provides a service port, this is just a declaration, and this port will not be opened at runtime because of this declaration. CMD: the startup command used to specify the default container main process (the container is the process, and you need to specify the program and parameters to run when starting the container). Dockerfile best practices
Partial excerpt
COPY is required to be used as much as possible in Docker's official Dockerfile best practices documentation, because the semantics of COPY is clear, just copying files, and ADD is best suited for scenarios that need to be automatically extracted.
It is also important to note that the ADD directive invalidates the image build cache, which may make the image build slower.
The CMD instruction is used to execute the software contained in the target image can contain parameters, and CMD should in most cases use CMD ["executable", "param1", "param2".] For example, CMD ["nginx", "- g", "daemon off;"]
The difference between RUN and CMD is that RUN is executed when the image is built, while CMD is executed in the container after the image is successfully built.
Please refer to document No. 2 for more information.
Reference article
Doker&k8s Qun [703906133]
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.