Docker
- docker基除命令
- 運行 Centos7容器
- 查看本地鏡像
- 查看容器
- 啟動一個已經停止的容器
- 進入和退出容器
- 停止容器
- 洗掉容器
docker基除命令
運行 Centos7容器
docker run -it centos:7
子命令 選項 鏡像名稱:標簽
i 持續保持的意思
t 分配一個tty終端鏈接
- 假如運行的鏡像不在本地,會自動從 Docker hub (鏡像倉庫)下載到本地,之后再運行,
[root@docker /]# docker run -it centos:7
Unable to find image 'centos:7' locally
7: Pulling from library/centos
75f829a71a1c: Pull complete
Digest: sha256:19a79828ca2e505eaee0ff38c2f3fd9901f4826737295157cc5212b7a372cd2b
Status: Downloaded newer image for centos:7
[root@652278f57c36 /]# 進入容器了
查看本地鏡像
- 使用命令 docker images 或者 docker image ls
[root@docker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 8652b9f0cb4c 4 months ago 204MB
hello-world latest bf756fb1ae65 15 months ago 13.3kB
[root@docker /]#
[root@docker /]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos 7 8652b9f0cb4c 4 months ago 204MB
hello-world latest bf756fb1ae65 15 months ago 13.3kB
[root@docker /]#
查看容器
- 查看所有的容器
[root@docker /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
652278f57c36 centos:7 "/bin/bash" 3 minutes ago Exited (0) About a minute ago upbeat_driscoll
c80c3601b538 hello-world "/hello" 15 minutes ago Exited (0) 15 minutes ago hopeful_lumiere
4508a9b84140 centos:7 "bash" 23 minutes ago Exited (0) 23 minutes ago vigilant_wiles
46686241dc6a centos:7 "bash" 37 minutes ago Exited (0) 37 minutes ago thirsty_heisenberg
[root@docker /]#
- 查看開啟狀態的容器
[root@docker /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
652278f57c36 centos:7 "/bin/bash" 5 minutes ago Up 4 seconds upbeat_driscoll
[root@docker /]#
啟動一個已經停止的容器
docker start bcbf2db9ae6a
容器 ID
進入和退出容器
docker exec -it bcbf2 bash
容器 ID 容器內的命令
- 容器 ID 不必寫全,只要保證可以識別到唯一的容器即可
[root@docker /]# docker exec -it 6522 bash
[root@652278f57c36 /]# exit
[root@docker /]#
停止容器
docker stop bcbf
容器 ID
[root@docker /]# docker stop 6522
6522
[root@docker /]#
洗掉容器
- 洗掉已經停止的容器
docker rm 容器 ID/容器名稱
docker ps -a -f status=exited 過濾除已經退出狀態的容器
[root@docker /]# docker ps -a -f status=exited
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
652278f57c36 centos:7 "/bin/bash" 14 minutes ago Exited (137) 4 minutes ago upbeat_driscoll
c80c3601b538 hello-world "/hello" 26 minutes ago Exited (0) 26 minutes ago hopeful_lumiere
4508a9b84140 centos:7 "bash" 34 minutes ago Exited (0) 34 minutes ago vigilant_wiles
46686241dc6a centos:7 "bash" 47 minutes ago Exited (0) 47 minutes ago thirsty_heisenberg
docker ps -aq -f status=exited 只顯示ID
[root@docker /]# docker ps -aq -f status=exited
652278f57c36
c80c3601b538
4508a9b84140
46686241dc6a
[root@docker /]# docker rm $(docker ps -aq -f status=exited) 把已經停止的容器全部洗掉
652278f57c36
c80c3601b538
4508a9b84140
46686241dc6a
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/271279.html
標籤:其他
上一篇:大資料主要所學技術(簡介)
下一篇:Docker——四種網路模式決議
