4-Dockerfile mirrored

 

 

 

 

 

 

 

 

dockerfile keyword

Keyword effect Remark
FROM Specifies the base image Designated dockerfile based on that image building, the proposed format to write the whole registry / namespace / project: tag or registry / namespace / project: tag as aliasName
MAINTAINER author information This is used to indicate who wrote the dockerfile
LABEL label Tags can be used to identify dockerfile Label used instead of Maintainer ultimately docker image can be viewed in the basic information
RUN Excuting an order The default is the implementation of a command / bin / sh format: RUN command or the RUN [ "command", "param1", "param2"]
CMD Start a command vessel Providing starting container when the default format used in conjunction with commands and ENTRYPOINT CMD command param1 param2 or CMD [ "command", "param1", "param2"]
ENTRYPOINT Entrance Generally produce some execution on closed containers will be used with the CMD better use of the following will specifically say this thing
COPY Copy files Copy the file to the image build time wildcards can be used as long as the composite of filepath.Match rules go on the trip COPY source target if it is constructed from the standard output stream can not use this keyword
ADD add files build in time to add to the image file is not limited in the current context can build from a remote service ADD source target Note: target band name if / then will target folder as internal documents automatically inferred if not with / Jiang target as possible so a file
ENV Environment Variables Build time specified by the environment variable ENV format -e cover at startup container name = value ...
ARG Build parameters Build parameters only when the parameters used to build if there is then the value of the same name ENV ENV always overrides of arg
VOLUME It can be mounted outside the defined data volume Mount image can build those directories specified start time to the file system boot time using the -v binding container format VOLUME [ "directory"]
EXPOSE Exposed port When using a listening port container -p start to run custom container port bindings expose Format: EXPOSE 8080 or EXPOSE 8080 / udp If you do not listen tcp or udp then the default is tcp
WORKDIR Work list Inside the container specified working directory is automatically created if not created if the specified / using a relative path absolute address if it is not / So in the beginning of the path of a workdir
USER Users specify the execution Specifies the build or the user RUN CMD ENTRYPONT executed when the user startup
HEALTHCHECK health examination Designated monitor the health monitoring of the current container command basically useless because very often the application itself has health monitoring mechanism
ONBUILD trigger When there is a mirror ONBUILD keywords as when the base image after the completion of the implementation FROM ONBUILD will execute commands but does not affect the usefulness of the current mirror is not how big
stoplight An amount of a transmission signal to the host The STOPSIGNAL setting instruction will be sent to the container to exit the system call signals. This signal may be a kernel system call table in a position matching valid unsigned number, for example 9, or signal names SIGNAME format, e.g. SIGKILL. This is not understood and seems to be doing the host by interacting semaphore
SHELL Specifies the execution of the script shell RUN CMD ENTRYPOINT designated to execute commands when using a shell such as sh bash zsh powershell formats SHELL zsh

Need to pay attention to the routine

Select the build environment

Linux kernel version must be higher than 3.10
does not allow problems to build on windows pit father prone

CMD and ENTRYPOINT difference Contact

联系:
当存在ENTRYPOINT的时候 CMD成为了参数 ENTRYPOINT = ENTRYPOINT <CMD>
区别:
CMD 就是单纯的执行一段shell 当要为 CMD添加参数的时候 只能选择全部覆盖CMD命令
如果是ENTRYPOINT 那么可以直接在启动容器最后添加 参数 因为当入口是ENTRYPOINT的时候CMD就成为了ENTRYPOINT的参数

ADD 和COPY的区别联系

联系:都是把文件添加到容器的image中
区别:
COPY 只能读取当前构建的上下文 如果是从标准输出流构建 COPY无法使用
ADD 可以使用远程服务的文件目录

VOLUME挂载目录需要注意的

1: 如果宿主机是windows 不能挂载空目录、和c盘的目录
2: 在VOLUME之后的构建操作 都无法生效 要求 暴露挂载卷 必须在最后一步 声明

构建镜像的注意点

1: 尽量选择 微缩基础镜像 例如alpine 减少镜像的体积
2: 尽量不要打包无用的文件到镜像中 减少镜像的体积
3: 尽量删除 各种编译、下载、安装过程中产生的缓存文件 减少镜像体积
4: 尽量使用分阶段构建镜像 一步步的扩展镜像功能 避免多层数镜像的产生
5: 准确使用dockerfile的关键字 例如CMD 和ENTRYPOINT 、 COPY 和ADD

docker build -f dockerfile文件路径 -t 镜像名称:版本 镜像生成路径

 

 

Guess you like

Origin www.cnblogs.com/long5683/p/12462064.html