ARG CODE_VERSION=latest
FROM base:${CODE_VERSION}
RUN /bin/bash -c ‘source $HOME/.bashrc; echo $HOME‘
RUN /bin/bash -c ‘source $HOME/.bashrc;echo $HOME‘
RUN ["/bin/bash", "-c", "echo hello"]
RUN echo "Hello world"
MAINTAINER os4top16
LABEL maintainer="os4top16@gmail.com"
父镜像(基础镜像)中包含的标签在新镜像中任然存在,创建重复的标签,则最近应用的值将会覆盖之前设置的值。可以使用docker inspect查看镜像中的标签
LABEL "com.example.vendor"="ACME Incorporated"
LABEL com.example.label-with-value="foo"
LABEL version="1.0"
LABEL description="This text illustrates that label-values can span multiple lines."
LABEL multi.label1="value1" multi.label2="value2" other="value3"
LABEL multi.label1="value1" \
multi.label2="value2" \
other="value3"
要在运行容器时实际发布端口,请在docker run上使用-p标志发布并映射一个或多个端口,或使用-P标志发布所有公开的端口并将其映射到高阶端口(会随机指定端口),如例子3。
EXPOSE 80/tcp
EXPOSE 80/udp
使用-P标志发布所有公开的端口并将其映射到高阶端口
[root@localhost data]# docker run -itd --name 03 -P nginx
8f90cfdba786447a9445719a5ac1eed5272659c80664e9d1500a9951b8801ebb
[root@localhost data]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8f90cfdba786 nginx "nginx -g ‘daemon of…" 3 seconds ago Up 2 seconds 0.0.0.0:32768->80/tcp 03
`1. ENV myName="John Doe" myDog=Rex The Dog myCat=fluffy`
2.`ENV myName John Doe`
ENV myDog Rex The Dog
ENV myCat fluffy
ADD [--chown=:] ... ADD [--chown=:] ["",... ""]
ADD hom* /mydir/ ADD hom?.txt /mydir/
ADD test relativeDir/ ADD test /absoluteDir/
ADD --chown=55:mygroup files* /somedir/
ADD --chown=bin files* /somedir/
ADD --chown=1 files* /somedir/
ADD --chown=10:11 files* /somedir/
COPY [--chown=:] ... COPY [--chown=:] ["",... ""]
COPY test relativeDir/
COPY test /absoluteDir/
COPY --chown=55:mygroup files /somedir/ COPY --chown=bin files /somedir/ COPY --chown=1 files /somedir/ COPY --chown=10:11 files /somedir/
ENTRYPOINT ["executable", "param1", "param2"] (exec form, preferred) ENTRYPOINT command param1 param2 (shell form)
ENTRYPOINT ["top", "-b"]
$ docker run -it --rm --name test top -H
ENTRYPOINT exec top -b
$ docker run -it --rm --name test top
VOLUME /myvol
USER [:] or USER [:]
USER yundd
WORKDIR /path/to/workdir
WORKDIR /a WORKDIR b WORKDIR c RUN pwd
ONBUILD ADD . /app/src ONBUILD RUN /usr/local/bin/python-build --dir /app/src
HEALTHCHECK [OPTIONS] CMD command (check container health by running a command inside the container)
HEALTHCHECK NONE (disable any healthcheck inherited from the base image)
HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f
http://127.0.0.1:800/
|| exit 1
[root@localhost openresty]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2481edb4bfd5 yundd:v4 "/usr/bin/openresty …" 21 seconds ago Up 19 seconds (health: starting) 0.0.0.0:800->800/tcp openresty
SHELL ["executable", "parameters"]
FROM microsoft/windowsservercore
# Executed as cmd /S /C echo default
RUN echo default
# Executed as cmd /S /C powershell -command Write-Host default
RUN powershell -command Write-Host default
# Executed as powershell -command Write-Host hello
SHELL ["powershell", "-command"]
RUN Write-Host hello
# Executed as cmd /S /C echo hello
SHELL ["cmd", "/S", "/C"]
RUN echo hello
原文:https://www.cnblogs.com/os4top16/p/12621378.html