赞
踩
docker pull centos
docker run [可选参数] image
参数说明:
- --name="Name" # 容器名
-
- -d # 后台方式运行
-
- -it # 使用交互方式运行 查看容器内容
-
- -p # 指定容器端口
-
- -P # 随机指定端口
例如,启动并进入容器:
- [root@192 ~]# docker run -it centos /bin/bash
- [root@081da4d71b9f /]# ls
- bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
- [root@081da4d71b9f /]#
exit
例如:
- [root@192 ~]# docker run -it centos /bin/bash
- [root@000361735e96 /]# ls
- bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
- [root@000361735e96 /]# exit
- exit
- [root@192 ~]#
docker ps [参数选项]
参数选项:
- -a # 列出历史运行的容器
-
- -n= # 显示最近创建的容器
-
- -q # 显示容器编号
例如:
- [root@192 ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 000361735e96 centos "/bin/bash" About a minute ago Exited (0) About a minute ago determined_swartz
- e6c3827354c7 mysql "docker-entrypoint.s…" 2 minutes ago Exited (1) 2 minutes ago confident_cerf
- 081da4d71b9f centos "/bin/bash" 3 minutes ago Exited (0) 2 minutes ago recursing_williams
- 4faad9eeee5d centos "/bin/bash" 25 hours ago Exited (0) 23 hours ago epic_mclaren
- b6cd9f523eff centos "/bin/bash" 25 hours ago Exited (0) 25 hours ago blissful_lalande
- 129ae722b6a4 centos "/bin/bash" 25 hours ago Exited (0) 23 hours ago great_bhabha
- 046741dd1f06 centos "/bin/bash" 25 hours ago Exited (0) 25 hours ago inspiring_burnell
- 36334e32c2b6 centos "/bin/bash" 25 hours ago Exited (0) 25 hours ago adoring_moore
- 540acab799ad d1165f221234 "/hello" 9 days ago Exited (0) 9 days ago eager_noether
- 072d7504621d d1165f221234 "/hello" 9 days ago Exited (0) 9 days ago intelligent_antonelli
- [root@192 ~]#
按键操作命令:
Ctrl + P + Q
例如:
- [root@192 ~]# docker run -it centos
- [root@e1a1ad252475 /]# [root@192 ~]#
- [root@192 ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- e1a1ad252475 centos "/bin/bash" 15 seconds ago Up 14 seconds practical_lamport
- [root@192 ~]#
- docker rm 容器id # 删除指定容器
-
- docker rm -f $(docker ps -aq) # 删除所有容器
-
- docker ps -aq | xargs docker rm # 删除所有容器
例如:
- [root@192 ~]# docker rm -f $(docker ps -aq)
- e1a1ad252475
- 000361735e96
- e6c3827354c7
- 081da4d71b9f
- 4faad9eeee5d
- b6cd9f523eff
- 129ae722b6a4
- 046741dd1f06
- 36334e32c2b6
- 540acab799ad
- 072d7504621d
- [root@192 ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- [root@192 ~]#
注意:不能直接删除运行中的容器
- [root@192 ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- e1a1ad252475 centos "/bin/bash" 15 seconds ago Up 14 seconds practical_lamport
- [root@192 ~]#
- [root@192 ~]#
- [root@192 ~]#
- [root@192 ~]#
- [root@192 ~]# docker rm e1a1ad252475
- Error response from daemon: You cannot remove a running container e1a1ad252475df7b76ca74135c2b9a1efc4859b0b253350feba825d767e015e0. Stop the container before attempting removal or force remove
- [root@192 ~]#
容器启动
- docker start 容器id # 容器启动
-
- docker restart 容器id # 容器重启
-
- docker stop 容器id # 容器停止
-
- docker kill 容器id # 杀掉容器
例如:
- [root@192 ~]# docker ps -----------------查看容器
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 3fadac1354b0 centos "/bin/bash" 25 seconds ago Up 24 seconds eloquent_tharp
- [root@192 ~]# docker stop 3fadac1354b0 -----------容器停止
- 3fadac1354b0
- [root@192 ~]# docker ps
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- [root@192 ~]# docker ps -aq
- 3fadac1354b0
- [root@192 ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 3fadac1354b0 centos "/bin/bash" 52 seconds ago Exited (0) 14 seconds ago eloquent_tharp
- [root@192 ~]# docker restart 3fadac1354b0 -------------容器重启
- 3fadac1354b0
- [root@192 ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 3fadac1354b0 centos "/bin/bash" About a minute ago Up 2 seconds eloquent_tharp
- [root@192 ~]# docker kill 3fadac1354b0 ----------------杀掉容器
- 3fadac1354b0
- [root@192 ~]# docker ps -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 3fadac1354b0 centos "/bin/bash" About a minute ago Exited (137) 2 seconds ago eloquent_tharp
- [root@192 ~]#
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。