创建一个容器,不启动该容器:
[root@localhost ~]# docker create -it centos6 bash
d80e3c0fabc5cb2f57ada9f2bb2729af65cf5a017ab1d224ad4001de2a6480ab
需要加-a才能看到:
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d80e3c0fabc5 centos6 "bash" 32 seconds ago Created agitated_shtern
6a30c38e5dcd centos6 "bash" 6 hours ago Up 6 hours reverent_bartik
3bf4980a0b7e centos_with_net "/bin/bash" 25 hours ago Exited (137) 23 hours ago compassionate_brahmagupta
8245e4d19c73 centos "/bin/bash" 25 hours ago Exited (137) 23 hours ago determined_vaughan
启动容器:
[root@localhost ~]# docker start d80e3c0fabc5
d80e3c0fabc5
给容器自定义名字:
[root@localhost ~]# docker run -itd --name centos6_1 centos6 bash
fe6e1cdb1f20c1a9df5ad65de3de76b498bb3fa7cf47e79ea2f2b60c34f9db75
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe6e1cdb1f20 centos6 "bash" 27 seconds ago Up 26 seconds centos6_1
d80e3c0fabc5 centos6 "bash" 18 minutes ago Up 14 minutes agitated_shtern
6a30c38e5dcd centos6 "bash" 6 hours ago Up 6 hours reverent_bartik
进入容器(可以用自己的命名):
[root@localhost ~]# docker exec -it centos6_1 bash
[root@fe6e1cdb1f20 /]#
[root@localhost ~]# docker run -itd centos bash -c "echo 123"
6ee156ea00ce1288049be56e5cbb6e4fcb4c857ced4bbd5a065316811451a80b
[root@localhost ~]# docker logs 6ee156ea00ce1288049be5
123
exit后,容器依然运行:
[root@localhost ~]#docker exec -it fe6e1cdb1f20 bash
导出容器迁移到其他机器上:
[root@localhost ~]# docker export 6ee156ea00ce1288049be5 > file.tar