6.10 docker (二) 守护态运行

 

守护态运行 

需要让Docker在后台运行而不是直接把执行命令的结果输出在当前宿主机下。此时,可以通过添加-d参数来实现

如果使用不-d参数运行容器。

[root@node ~]# docker run ubuntu:18.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
hello world
hello world
hello world
hello world

容器会把输出的结果(STDOUT)打印到宿主机上面

如果了使用-d参数运行容器

[root@node ~]# docker run -d ubuntu:18.04 /bin/sh -c "while true; do echo hello worl sleep 1; done"

[root@node ~]# docker container ls

原文地址:https://www.cnblogs.com/guogle/p/11000013.html