李明
|
官网学习
FROM
FROM <image> FROM <image>:<tag> FROM <image>@<digest> FROM scratch #制作base ImageFROM centos #使用base ImageFROM centos:7.9 FROM mysql:5.6
LABEL
LABEL maintainer="394498036@qq.com"LABEL version="1.0"LABEL description="This is description \ 欢迎关注:编程坑太多,我在等你."
RUN
RUN yum update && yum install -y vim \ python-dev #反斜线换行 RUN apt-get update && apt-get install -y perl \ pwgen --no-install-recommends && rm -rf \ /var/lib/apt/lists/* #注意清理cache RUN /bin/bash -c 'source $HOME/.bashrc;echo $HOME'
WORKDIR
WORKDIR /test #如果没有会自动创建test目录WORKDIR jianshu RUN pwd #输出结果应该是/test/jianshu
ADD and COPY
ADD <src>... <dest> ADD ["<src>",... "<dest>"] 用于支持包含空格的路径 COPY <src>... <dest> COPY ["<src>",... "<dest>"] 用于支持包含空格的路径 ADD hello / ADD test.tar.gz / #添加到根目录并解压WORKDIR /root ADD hello test/ # /root/test/hello WORKDIR /root COPY hello test/ # /root/test/hello
ENV
ENV <key> <value> ENV <key>=<value> ... ENV MYSQL_VERSION 5.6 E-NV apt-get install -y mysql-server = "${MYSQL_VERSION}" \ && rm -rf /var/lib/apt/lists/* #引用常亮
学习下面的先了解下
RUN apt-get install -y vim CMD echo "hello docker 微信公众号:编程坑太多"ENTRYPOINT echo "hello docker 微信公众号:编程坑太多"
RUN ["apt-get", "install", " -y", "vim"] CMD ["/bin/echo","hello docker 微信公众号:编程坑太多"] ENTRYPOINT ["/bin/echo","hello docker 微信公众号:编程坑太多"]
FROM centos ENV name Docker ENTRYPOINT echo "hello $name"
FROM centos ENV name Docker ENTRYPOINT ["/bin/echo", "hello $name"]
mkdir cmd-entrrypointcd cmd-entrrypoint/ vi Dockerfile
more Dockerfile
docker build -t liming/centos-entrypoint-shell .
docker run liming/centos-entrypoint-shell
more Dockerfile
docker build -t liming/centos-entrypoint-exec .
docker run liming/centos-entrypoint-exec
FROM centos ENV name Docker ENTRYPOINT ["/bin/bash","-c", "echo hello $name"]
docker build -t liming/centos-entrypoint-exec-new .
docker run liming/centos-entrypoint-exec-new
CMD
FROM centos ENV name Docker CMD echo "hello $name" docker build -t liming/centos-cmd-shell . docker run liming/centos-cmd-shell docker run -it liming/centos-cmd-shell /bin/bash ENTRTYPOINT
FROM centos ENV name Docker ENTRYPOINT echo "hello $name" docker build -t liming/centos-entrypoint-shell . docker run liming/centos-entrypoint-shell docker run -it liming/centos-entrypoint-shell /bin/bash 个人网站: IT人故事会 idig8.com PS:Dockerfile详解基本就介绍这么多,可能还有很多命令没有讲解,以后用到了在说吧。一定要CMD和ENTRTYPOINT因为很多官方的都常用这两个命令。 往期精彩 |
2018-08-30 09:33:14