docker的經常使用命令彙總

docker的經常使用命令彙總

2017年12月07日 15:09:48docker

閱讀數:3411centos

     具體docker的優點我就不說了,下面就使用docker的一些經常使用命令具體詳細說下:bash

一、docker的啓動、中止、重啓

 
  1. [root@localhost ~]# service docker restartapp

  2. Redirecting to /bin/systemctl restart docker.servicepost

  3. [root@localhost ~]# service docker stopspa

  4. Redirecting to /bin/systemctl stop docker.service.net

  5. [root@localhost ~]# service docker startrest

  6. Redirecting to /bin/systemctl start docker.service日誌

二、docker建立一個容器

  

 
  1. [root@localhost ~]# docker run -it -v /docker_test:/yufei --name yufei_6 centoscode

  2. [root@724e7701f0d4 /]#

   -i:容許咱們對容器內的 (STDIN) 進行交互

  -t:在新容器內指定一個僞終端或終端

 -v:是掛在宿機目錄, /docker_test是宿機目錄,/yufei是當前docker容器的目錄,宿機目錄必須是絕對的。

--name:是給容器起一個名字,可省略,省略的話docker會隨機產生一個名字

三、docker啓動的容器列表

 
  1. [root@localhost ~]# docker ps

  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

  3. 724e7701f0d4 centos "/bin/bash" 4 minutes ago Up 4 minutes yufei_6

  4. f9097691663e centos "/bin/bash" 5 minutes ago Up 5 minutes yufei_5

  5. [root@localhost ~]#

三、查看docker建立的全部容器

 
  1. [root@localhost ~]# docker ps -a

  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

  3. 724e7701f0d4 centos "/bin/bash" 5 minutes ago Up 5 minutes yufei_6

  4. f9097691663e centos "/bin/bash" 6 minutes ago Up 6 minutes yufei_5

  5. e59a540fb979 centos "/bin/base" 6 minutes ago Created yufei_4

  6. ff49dfedea4f centos "/bin/bash" 2 hours ago Exited (137) 10 minutes ago yufei_03

  7. d2cc70abb5a5 centos "/bin/bash" 2 hours ago Exited (127) 2 hours ago yufei_02

  8. 2d48fc5b7c17 centos "/bin/bash" 2 hours ago Exited (127) 2 hours ago yufei_01

  9. [root@localhost ~]#

 docker ps 默認列表是正在啓動的容器 -a是顯示全部建立的容器

四、啓動、中止、重啓某個docker 容器

 
  1. [root@localhost ~]# docker start yufei_01

  2. yufei_01

  3. [root@localhost ~]# docker stop yufei_01

  4. yufei_01

  5. [root@localhost ~]# docker restart yufei_01

  6. yufei_01

  7. [root@localhost ~]#

五、查看指定容器的日誌記錄

 
  1. <span style="color:#333333;">[root@localhost ~]# docker logs -f yufei_01

  2. </span><span style="background-color:rgb(51,204,255);"><span style="color:#ff0000;">[root@2d48fc5b7c17 /]# ls

  3. anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var

  4. [root@2d48fc5b7c17 /]# exit

  5. exit

  6. [root@2d48fc5b7c17 /]# ls

  7. anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var

  8. [root@2d48fc5b7c17 /]#

  9. [root@2d48fc5b7c17 /]#

  10. [root@2d48fc5b7c17 /]#

  11. [root@2d48fc5b7c17 /]#

  12. [root@2d48fc5b7c17 /]#

  13. [root@2d48fc5b7c17 /]#

  14. [root@2d48fc5b7c17 /]#

  15. [root@2d48fc5b7c17 /]# cd /

  16. [root@2d48fc5b7c17 /]# ls

  17. anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var

  18. [root@2d48fc5b7c17 /]# mkdir yufei

  19. [root@2d48fc5b7c17 /]# ls

  20. anaconda-post.log bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var yufei

  21. [root@2d48fc5b7c17 /]# cd yufei

  22. [root@2d48fc5b7c17 yufei]# ls

  23. yufei

  24. [root@2d48fc5b7c17 yufei]# cd yufei

  25. [root@2d48fc5b7c17 yufei]# ls

  26. application

  27. [root@2d48fc5b7c17 yufei]# cd ../../

  28. [root@2d48fc5b7c17 /]# rm -rf yufei

  29. [root@2d48fc5b7c17 /]# eixt

  30. bash: eixt: command not found

  31. [root@2d48fc5b7c17 /]# exit

  32. exit</span></span><span style="color:#333333;">

  33. [root@2d48fc5b7c17 /]# </span>


上面紅色部分是日誌命令部分。

六、刪除某個容器,若正在運行,須要先中止

 
  1. [root@localhost ~]# docker rm yufei_01

  2. Error response from daemon: You cannot remove a running container 2d48fc5b7c17b01e6247cbc012013306faf1e54f24651d5e16d6db4e15f92d33. Stop the container before attempting removal or use -f

  3. [root@localhost ~]# docker stop yufei_01

  4. yufei_01

  5. [root@localhost ~]# docker rm yufei_01

  6. yufei_01

  7. [root@localhost ~]#

七、刪除全部容器

 
  1. [root@localhost ~]# docker rm $(docker ps -a -q)

  2. Error response from daemon: You cannot remove a running container 724e7701f0d4a830167e21f75b470235a0e408fd6cc2913403426e96f69cba11. Stop the container before attempting removal or use -f

  3. Error response from daemon: You cannot remove a running container f9097691663ee36f9d2ee56afbdcca0eeb8b63e5590ddf18c0c42954c93b9f06. Stop the container before attempting removal or use -f

  4. [root@localhost ~]#

  5. [root@localhost ~]#

  6. [root@localhost ~]# docker stop yufei_6

  7. yufei_6

  8. [root@localhost ~]# docker stop yufei_5

  9. yufei_5

  10. [root@localhost ~]# docker rm $(docker ps -a -q)

  11. 724e7701f0d4

  12. f9097691663e

  13. [root@localhost ~]#

相關文章
相關標籤/搜索