ENTRYPOINT用法php
entrypoint在dockerfile当中只有最后一条生效,其余entrypoint都不生效
第一种写法相似数组形式,推荐使用。使用这种方法启动的进程的pid
为1
。
第二章方法执行命令启动的进程,该进程的pid
为执行完这个shell的pid
。mysql
CMD用法nginx
第一种用法,也是数组格式。
第二种用法,为entrypoint指定参数。好比,entrypoint执行命令 usrs/bin/Nginx
,cmd能够提供参数如start
,结合起来即为usrs/bin/nginx start
.
第三种写法,pid号也是shell执行的pid
号。是Linux下 /bin/sh -c
的用法。git
构建镜像须要基于一个基础镜像。下面基于centos7这个基础镜像构建一个镜像。sql
[root@Optimus /]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE wordpress latest b027afd30886 33 hours ago 409.2 MB csphere/wordpress 4.2 6d90342cc99d 2 days ago 747.3 MB csphere/mysql 5.5 e147ac2a588e 6 days ago 752.7 MB csphere/php-fpm 5.4 1b08c94ce801 8 days ago 709.7 MB csphere/centos 7.1 fd1f7619e63e 9 days ago 613 MB centos centos7.1.1503 879c6d07c60e 7 weeks ago 212.1 MB [root@Optimus /]#
-----
使用cmddocker
建立dockerfileshell
[root@Optimus /]# vim Dockerfile FROM centos:centos7.1.1503 CMD ["/bin/echo", "This is test cmd"]
build的时候出错,提示没有权限vim
[root@Optimus /]# docker build -t csphere/cmd:0.1 . Error checking context is accessible: 'no permission to read from 'proc/sys/net/ipv4/route/flush''. Please check permissions and try again.
删除Dockerfilecentos
rm -rf 目录名字 -r 就是向下递归,无论有多少级目录,一并删除 -f 就是直接强行删除,不做任何提示的意思~ rm -rf Dockerfile
进入docker-training目录下面,从新建立Dockerfile,构建镜像数组
[root@Optimus docker-training]# docker build -t csphere/cmd:0.1 docker: "build" requires 1 argument. See 'docker build --help'. Usage: docker build [OPTIONS] PATH | URL | - Build a new image from the source code at PATH [root@Optimus docker-training]# docker build -t csphere/cmd:0.1 . Sending build context to Docker daemon 27.55 MB Sending build context to Docker daemon Step 0 : FROM centos:centos7.1.1503 ---> 879c6d07c60e Step 1 : CMD /bin/echo This is test cmd ---> Running in 3dce9e75bdc8 ---> f32bb73e8383 Removing intermediate container 3dce9e75bdc8 Successfully built f32bb73e8383 [root@Optimus docker-training]#
接下来能够经过csphere/cmd:0.1
这个镜像来启动一个容器
docker run -it --rm --rm参数的意识是,只要容器一退出,则删除容器 [root@Optimus docker-training]# docker run -it csphere/cmd:0.1 This is test cmd 能够看到,/bin/echo This is test cmd 这条命令成功执行。
直接进入container里面,而不执行echo指令,能够在docker run 后面直接加上/bin/bash命令,/bin/bash命令会覆盖掉cmd后面的命令。
[root@Optimus docker-training]# docker run -it csphere/cmd:0.1 /bin/bash [root@cd32d71fb9c5 /]# /bin/bash 命令覆盖掉了dockerfile中的cmd命令,直接进入到了container中。
---
使用entrypoint
[root@Optimus docker-training]# vim Dockerfile FROM centos:centos7.1.1503 ENTRYPOINT ["/bin/echo", "This is test entrypoint"] ~
构建镜像
[root@Optimus docker-training]# docker build -t csphere/ent:0.1 . Sending build context to Docker daemon 27.55 MB Sending build context to Docker daemon Step 0 : FROM centos:centos7.1.1503 ---> 879c6d07c60e
直接在docker run 后面加参数/bin/bash,entrypoint会把/bin/bash当成一个echo的字符串参数,不会进入到容器中。
[root@Optimus docker-training]# docker run -it csphere/ent:0.1 /bin/bash This is test entrypoint /bin/bash
若是想覆盖dockerfile中entrypoint指令,能够在docker run命令中加--entrypoint参数来指定。
[root@Optimus docker-training]# docker run -it --entrypoint=/bin/bash csphere/ent:0.1 [root@bc7378b9ca83 /]# Step 1 : ENTRYPOINT /bin/echo This is test entrypoint ---> Running in 40b01fac38af ---> 9714a8b5bb85 Removing intermediate container 40b01fac38af Successfully built 9714a8b5bb85 [root@Optimus docker-training]#
启动容器
[root@Optimus docker-training]# docker run -it csphere/ent:0.1 This is test entrypoint
----
其余
删除镜像
docker rmi 镜像 若是有启动中的容器正在使用该镜像,不能删除该镜像。删除镜像前,先中止container。-f 参数强制删除镜像。
若是对文件有修改,能够使用一下命令,更新git 仓库
git add * git commit -M "" git push origin master 提交到本身的仓库中