1.docker创建一个容器
[root@localhost ~]# docker run -it -v /root/test/:/yunwei --name gaki01 centos:latest
[root@3f5ec2a95efd /]#
参数释义:-i:允许我们对容器内的(STDIN)进行交互
-t:在新容器内指定一个伪终端或终端
-v:是挂在宿主机的目录并可以指定创建容器后再创建相关的目录,此句命令中/root/test/为容器所在的宿主目录,/yunwei为当前docker的新建目录,宿主机目录必须是绝对路径。
--name:为新建容器起名,如果省略,系统会随机产生一个个名字。
2.查看容器
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f5ec2a95efd centos:latest "/bin/bash" 13 minutes ago Up 13 minutes gaki01
bdd020180c3f centos-gaki:v1 "/bin/bash /run-ht..." 2 hours ago Up 2 hours 80/tcp dazzling_joliot
7a798aeaccf7 centos:latest "/bin/bash" 4 hours ago Up 4 hours c1
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f5ec2a95efd centos:latest "/bin/bash" 14 minutes ago Up 14 minutes gaki01
bdd020180c3f centos-gaki:v1 "/bin/bash /run-ht..." 2 hours ago Up 2 hours 80/tcp dazzling_joliot
7a798aeaccf7 centos:latest "/bin/bash" 4 hours ago Up 4 hours c1
ps:查看的是当前启动的容器
-a/–all:查看所有的容器
3.删除所有容器(容器在删除时要先关闭)
[root@localhost ~]# docker rm $(docker ps -a -q)
Error response from daemon: You cannot remove a running container 3f5ec2a95efd3a69b4a4975f2639667b76be5d7434045d100d8bc27b9c410652. Stop the container before attempting removal or use -f
Error response from daemon: You cannot remove a running container bdd020180c3fcc5997a73586994b975562c96255f018ba5ffff5968ce0361708. Stop the container before attempting removal or use -f
[root@localhost ~]#