环境:centos7.2,镜像centos7
方法1,run一个容器:
[root@localhost ~]# docker run -dit --hostname centos --name centos --restart always a8493f5f50ff /bin/bash -dit 是后台运行、交互模式、分配终端,容器启动后不会退出 如果没有it参数,run 一个容器以后,docker ps -a 容器状态就exited了 --restart always 容器可以随docker服务启动而启动
方法2: run 一个容器,并一直发送ping包
[root@localhost ~]# docker run -d --name test --hostname test a8493f5f50ff ping 127.0.0.1
这样容器就一直在发送ping包,不会退出。
意思就是然容器一直运行一个程序,不退出,容器就不会停止
推荐第一种
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/3736.html