1.容器 -t -i -d start stop restart export import load
1.1启动/停止容器
1.1.1
root@vmc01:~/ljp/docker# docker run ubuntu /bin/echo "Hello Word" Hello Word
1.1.2
root@vmc01:~/ljp/docker# docker run -t -i ubuntu:v2_163 /bin/bash root@75a255f3778c:/#
1.1.3
启动已经停止运行的容器
root@vmc01:~/ljp/docker# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8f3efc871be6 ubuntu:v2_163 "/bin/bash" 28 seconds ago Exited (0) 28 seconds ago prickly_feynman root@vmc01:~/ljp/docker# docker start 8f3efc871be6
1.1.4
容器以守护状态运行
root@vmc01:~/ljp/docker# docker run -d ubuntu /bin/bash -c "while true;do echo hello word;sleep 2;done" 2a4cfee905eb127a716986bcd2a9d9523d3b0585dea7ba4d7fef1e0ac26181c4 root@vmc01:~/ljp/docker# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2a4cfee905eb ubuntu:latest "/bin/bash -c ‘while 17 seconds ago Up 17 seconds condescending_archimedes 8f3efc871be6 ubuntu:v2_163 "/bin/bash" 26 minutes ago Exited (0) 24 minutes ago prickly_feynman 相当于将docker放置在后台执行,在不加-d 的情况容器输出下会直接输出在当前屏幕,加了-d之后需要使用docker logs containerID查看 程序执行的快慢和-d无关,和程序本身有关
1.1.5
停止容器
root@vmc01:~/ljp/docker# docker stop 2a4cfee905eb 2a4cfee905eb root@vmc01:~/ljp/docker# root@vmc01:~/ljp/docker# docker ps -a CONTAINER ID IMAGE 2a4cfee905eb ubuntu:latest "/bin/bash -c ‘while 7 minutes ago Exited (137) 4 seconds ago condescending_archimedes 8f3efc871be6 ubuntu:v2_163 "/bin/bash" 33 minutes ago Exited (0) 31 minutes ago prickly_feynman
1.1.6
重启
docker restart 2a4cfee905eb
1.2删除容器
1.2.1
删除停止状态的容器
root@vmc01:~/ljp/docker# docker rm 2a4cfee905eb 2a4cfee905eb
1.2.2
删除运行状态的容器
root@vmc01:~/ljp/docker# docker rm -f 8f3efc871be6 8f3efc871be6
1.3容器导出导入
1.3.1
导出容器
root@vmc01:~/ljp/docker# docker export 02befc990ba2 > ubuntu.tar
1.3.2导入容器
root@vmc01:~/ljp/docker# cat ubuntu.tar | docker import - test/ubuntu:v1 root@vmc01:~/ljp/docker# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE test/ubuntu v1 e8206b6e415b 2 seconds ago 187.7 MB
同样可以使用docker load 导入
本文出自 “lijp” 博客,请务必保留此出处http://jiapeng.blog.51cto.com/6706171/1739941
原文地址:http://jiapeng.blog.51cto.com/6706171/1739941