dockerfile note
dockerfile note
reference
summary
defination
docker can build images automatically by reading the instructions from a dockerfile. dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.usage
thedocker build
command builds an image from a dockerfile and context. the build's context is the set of files at a specified location PATH or URL. warning: don't use PATH/
, because it can transfer the entire contents of your hard drive to the docker daemon.
docker build -f /home/vickey/dockerfile .
- format
a. INSTRUCTION is not case-sensitive but convention is UPPERCASE. e.g:FROM nginx:1.13
b. must start withFROM
.c. docker treat lines begin with
#
as a comment. - parser directive
reference
a. parser directive is not case-sentive but convention is lowercase and must at the first line of dockerfile e.g:# directive=value
then the next line isFROM nginx:1.13
b. can't repeat
escape
in linux default is\
, " ` " in windowsvariable replacement
${variable:-word} indicates that ifvariable
is set then the result will be that value. Ifvariable
is not set thenword
will be the result.
${variable:+word} indicates that ifvariable
is set thenword
will be the result, otherwise the result is the empty string..dockerignore file
Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context. If this file exists, the CLI modifies the context to exclude files and directories that match patterns in itFROM
The tag or digest values are optional. If you omit either of them, the builder assumes a latest tag by default
FROM buildpack-deps:jessie
RUN
RUN /bin/bash -c 'source $HOME/.bashrc; \ echo $HOME'
equivalent to following
RUN /bin/bash -c 'source $HOME/.bashrc; echo $HOME'
CMD
There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect
CMD echo "This is a test." | wc -
LABEL
A LABEL is a key-value pair.
LABEL version="1.0"
To view an image’s labels, use the docker inspect command
docker inspect docker container name
EXPOSE
By default, EXPOSE assumes TCP. You can also specify UDP:
EXPOSE 80/udp
or publish port when run images
docker run -p 80:80/tcp -p 80:80/udp image_name
ENV
The entire string after the first space will be treated as the - including whitespace characters. allows for multiple variables to be set at one time
ENV myName John Doe ENV myDog Rex The Dog
equivalent tiENV myName = John Doe
ADD
TheADD
instruction copies new files, directories or remote file URLs from and adds them to the filesystem of the image at the pathCOPY
The COPY instruction copies new files or directories from<src>
and adds them to the filesystem of the container at the path<dest>
.
COPY VS ADDVOLUME
The VOLUME instruction creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers. The value can be a JSON array,VOLUME ["/var/log/"]
, or a plain string with multiple arguments, such asVOLUME /var/log
orVOLUME /var/log/var/db
WORKDIR
The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile
WORKDIR /path/to/workdir RUN pwd
最新文章
- unity游戏在logcat中过滤一些不需要的Log
- js表单提交,面向对象
- Oracle中用一个表的数据更新另一个表的数据
- C#线程同步总结
- 各种sensor名称统计
- ACE的安装方法
- .net防止刷新重复提交(转)
- 【转】三星8552 手机提示升级系统 完成后重启 开机画面一直停留在三星的LOGO 一闪一闪 怎么办
- IE6 png图片实现半透明的方法
- hdu 1290 竭诚为杭州电礼物50周年
- AutoMapper IIS回收引发的 未将对象引用设置到对象实例
- Win7系统 mstsc远程桌面连接失败,提示“您的凭据不工作” 或者“无法连接到远程计算机”的问题。
- SQL Server 高并发Insert数据解析,实践
- idou老师教你学istio :基于角色的访问控制
- 20155217 2016-2017-2 《Java程序设计》第4周学习总结
- PHP扩展功能 ---- 伪静态
- I、Python 环境搭建
- linux 的空命令:(冒号)
- idea Jetty deployment
- oracle的时间