》一文中介绍过 1 号进程对容器中信号处理的重要性,感兴趣的朋友可以移步进行了解。下面我们通过 CMD 指令来学习 exec 模式和 shell 模式的特点。
[ "top" ]
$ docker build --idt --name testcon test1
$ docker exec testcon aux
》)。
exec 模式的特点是不会通过 shell 执行相关的命令,所以像 $HOME 这样的环境变量是取不到的:
[ "echo","$HOME" ]
$ docker build --no-cache --- test1
[ "sh","-c","echo $HOME" ]
$ docker build --no-cache --- test1
top
$ docker build --itd --name testcon2 test2
$ docker exec testcon2 aux
:CMD ["executable","param1","param2"] // 这是 exec 模式的写法,注意需要使用双引号。CMD command param1 param2 // 这是 shell 模式的写法。
[ "top" ]
ENTRYPOINT ["executable","param2"] // 这是 exec 模式的写法,注意需要使用双引号。ENTRYPOINT command param1 param2 // 这是 shell 模式的写法。
指定 ENTRYPOINT 指令为 exec 模式时,命令行上指定的参数会作为参数添加到 ENTRYPOINT 指定命令的参数列表中。用下面的代码构建镜像 test1:
[ "top","-b" ]
$ docker run -- test1 -c
[ "top","-b" [ "-c" ]
$ docker run -- test2
$ docker run -- test2 -n
echo $HOME
$ docker run -- --entrypoint test2