docker create/start 命令

docker 容器状态有一种是create,他的意思是创建了容器,但是还没启动,创建完成后,需要使用start来启动容器

我们可以试一下

先创建容器

[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7103a04f97d3 ubuntu:14.04 "/bin/bash" 3 hours ago Up 3 hours ubuntu
[root@localhost ~]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 14.04 2c5e00d77a67 7 weeks ago 188MB
[root@localhost ~]# docker create --name ubuntu_2 ubuntu:14.04
dca3d42e5e3ef9feaf0b0a1fb2a54700e8fe026b757845ffe36e3ca30e846f5a
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dca3d42e5e3e ubuntu:14.04 "/bin/bash" 4 seconds ago Created ubuntu_2
7103a04f97d3 ubuntu:14.04 "/bin/bash" 3 hours ago Up 3 hours ubuntu

注意观察上面ubuntu_2的状态是Created,而不是时间

然后才是start容器

[root@localhost ~]# docker start ubuntu_2 
ubuntu_2
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dca3d42e5e3e ubuntu:14.04 "/bin/bash" 6 minutes ago Exited (0) 2 seconds ago ubuntu_2
7103a04f97d3 ubuntu:14.04 "/bin/bash" 3 hours ago Up 3 hours ubuntu

可以看到,这个容器,启动后就退出了,因为没有任何交互,要想留在后台,需要使用run

[root@localhost ~]# docker run -itd --name ubuntu_3 ubuntu:14.04
be9d5c6f2a25bff5acaae6339cd1e2671a37cba8cec2029440f29ca967df09db
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be9d5c6f2a25 ubuntu:14.04 "/bin/bash" 4 seconds ago Up 3 seconds ubuntu_3
dca3d42e5e3e ubuntu:14.04 "/bin/bash" 8 minutes ago Exited (0) 2 minutes ago ubuntu_2
7103a04f97d3 ubuntu:14.04 "/bin/bash" 3 hours ago Up 3 hours ubuntu
此条目发表在Docker分类目录,贴了标签。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注