- 工信部備案號 滇ICP備05000110號-1
- 滇公安備案 滇53010302000111
- 增值電信業務經營許可證 B1.B2-20181647、滇B1.B2-20190004
- 云南互聯網協會理事單位
- 安全聯盟認證網站身份V標記
- 域名注冊服務機構許可:滇D3-20230001
- 代理域名注冊服務機構:新網數碼
Docker常用命令
幫助命令
docker indo #顯示docker系統信息,包括鏡像和容器的數量
docker --help #docker的版本信息
docker version #docker幫助命令
幫助文檔地址:
鏡像命令
docker images 查看所有本地主機上的鏡像
[16:24:31 root@hwcentos7 ~]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 18 months ago 13.3kB
#解釋:
REPOSITORY 鏡像的倉庫源
TAG 鏡像的標簽
IMAGE ID 鏡像ID
CREATED 鏡像的創建時間
SIZE 鏡像的大小
#可選項
-a, --all Show all images (default hides intermediate images)
-q, --quiet Only show image IDs 只顯示ID
docker search 搜索鏡像
[16:35:00 root@hwcentos7 ~]#docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 13980 [OK]
mariadb MariaDB Server is a high performing open sou… 5329 [OK]
#可選項
docker pull 下載鏡像
#可選項
-a, --all-tags Download all tagged images in the repository
--disable-content-trust Skip image verification (default true)
--platform string Set platform if server is multi-platform capable
-q, --quiet Suppress verbose output
docker pull mysql[:tags] #不指定版本 默認下載最新的
[16:37:33 root@hwcentos7 ~]#docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
72a69066d2fe: Pull complete #分層級下載
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
688ba7d5c01a: Pull complete
00e060b6d11d: Pull complete
1c04857f594f: Pull complete
4d7cfa90e6ea: Pull complete
e0431212d27d: Pull complete
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709 #防偽標識
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest #真實目錄
#指定版本下載
[16:44:25 root@hwcentos7 ~]#docker pull mysql:5.7
5.7: Pulling from library/mysql
72a69066d2fe: Already exists #已存在的層級不用重新下載
93619dbc5b36: Already exists
99da31dd6142: Already exists
626033c43d70: Already exists
37d5d7efb64e: Already exists
ac563158d721: Already exists
d2ba16033dad: Already exists
0ceb82207cd7: Pull complete
37f2405cae96: Pull complete
e2482e017e53: Pull complete
70deed891d42: Pull complete
Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
[16:47:59 root@hwcentos7 ~]#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 c20987f18b13 15 months ago 448MB
mysql latest 3218b38490ce 15 months ago 516MB
hello-world latest feb5d9fea6a5 18 months ago 13.3kB
docker rmi 刪除鏡像
[16:48:44 root@hwcentos7 ~]#docker rmi -f c20987f18b13
Untagged: mysql:5.7
Untagged: mysql@sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Deleted: sha256:c20987f18b130f9d144c9828df630417e2a9523148930dc3963e9d0dab302a76
Deleted: sha256:6567396b065ee734fb2dbb80c8923324a778426dfd01969f091f1ab2d52c7989
Deleted: sha256:0910f12649d514b471f1583a16f672ab67e3d29d9833a15dc2df50dd5536e40f
Deleted: sha256:6682af2fb40555c448b84711c7302d0f86fc716bbe9c7dc7dbd739ef9d757150
Deleted: sha256:5c062c3ac20f576d24454e74781511a5f96739f289edaadf2de934d06e910b92
docker rmi -f $(docker images -aq) #刪除全部鏡像
容器命令
有了鏡像才可以使用容器
docker安裝一個centos學習
docker pull centos
新建容器并啟動
docker run [可選參數] image
#可選參數
--name="Name" 指定容器名字
-d 后臺運行
-it 使用交互方式運行
-p 指定容器的端口 -p 8080:8080
-p 主機端口:容器端口 主機和容器端口的映射
-p ip主機端口:容器端口
-P 隨機指定端口
#測試
列出所有運行的容器
docker ps 命令
#列出當前正在運行的容器
-a #列出所有的容器,包括歷史的
-n=? #列出最近使用的幾個容器
-q #只顯示容器ID
[09:48:21 root@hwcentos7 ~]#docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[09:48:38 root@hwcentos7 ~]#docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8b564e71aa56 centos "/bin/bash" About a minute ago Exited (0) 19 seconds ago jolly_tharp
6d9203bc679f feb5d9fea6a5 "/hello" 18 hours ago Exited (0) 18 hours ago agitated_babbage
退出容器
exit 退出容器并停止
ctrl+p+q 退出容器不停止
刪除容器
docker rm #不能刪除正在運行的 -f可強制刪除
docker rm -f $(docker ps -aq)
啟動和停止容器
docker start 容器ID #啟動容器
docker restart 容器ID #重啟容器
docker stop 容器ID #停止正在運行的容器
docker kill 容器ID #強制停止
常用其他命令
查看日志
docker logs
-tf #顯示日志
--tail number #顯示日志條數
查看容器中的進程
docker top 容器ID
查看鏡像的元數據
docker inspect 容器ID
進入當前正在運行的容器
#方式一 進入容器后打開新的終端
docker exec -it 容器ID /bin/bash
#方式二 正在執行當前的代碼 沒有打開新的終端
docker attach 容器ID
從容器內拷貝文件到主機
docker cp 容器ID:容器內文件路徑 目的主機路徑
docker volume 查看所有卷的情況
所有的docker容器內的卷,都在/var/lib/docker/volumes/下
提交成功!非常感謝您的反饋,我們會繼續努力做到更好!
這條文檔是否有幫助解決問題?
售前咨詢
售后咨詢
備案咨詢
二維碼
TOP