一、幫助命令
docker version #顯示docker的版本資訊
docker info #顯示docker的系統資訊,包括鏡像和容器的數量
docker 命令 --help #幫助命令
幫助檔案地址:https://docs.docker.com/engine/reference/commandline/cli/
二、鏡像命令
docker images #查看所有本地的主機的鏡像
eg:
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat latest b0e0b0a92cf9 2 weeks ago 680MB
nginx latest 87a94228f133 3 weeks ago 133MB
hello-world latest feb5d9fea6a5 6 weeks ago 13.3kB
#解釋:
REPOSITORY #鏡像的倉庫源
TAG #鏡像的標簽
IMAGE ID #鏡像的ID
CREATED #鏡像的創建時間
SIZE #鏡像的大小
#可選項(常用)
-a #列出所有鏡像(默認也會列出所有鏡像)
-q #只顯示鏡像的ID
#了解更多
docker images --help
docker search 鏡像名 #搜索鏡像(建議去docker hub的web頁面上搜)
eg:
[root@localhost ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11647 [OK]
mariadb MariaDB Server is a high performing open sou… 4433 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 864 [OK]
#可選項(常用)
--filter #根據提供的條件篩選輸出
eg:
[root@localhost ~]# docker search mysql --filter=STARS=3000 #搜索出來的都是STARS大于3000的
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11647 [OK]
mariadb MariaDB Server is a high performing open sou… 4433 [OK]
#了解更多
docker search --help
docker pull 鏡像名:tag #下載鏡像
eg:
[root@localhost ~]# docker pull mysql
Using default tag: latest #如果不寫tag,默認就是latest(最新版)
latest: Pulling from library/mysql
b380bbd43752: Already exists #分層下載,docker image的核心,聯合檔案系統
f23cbf2ecc5d: Pull complete
30cfc6c29c0a: Pull complete
b38609286cbe: Pull complete
8211d9e66cd6: Pull complete
2313f9eeca4a: Pull complete
7eb487d00da0: Pull complete
4d7421c8152e: Pull complete
77f3d8811a28: Pull complete
cce755338cba: Pull complete
69b753046b9f: Pull complete
b2e64b0ab53c: Pull complete
Digest: sha256:6d7d4524463fe6e2b893ffc2b89543c81dec7ef82fb2020a1b27606666464d87 #簽名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest #真實地址
#等價
docker pull mysql 等價于 docker pull docker.io/library/mysql:latest
#指定版本下載
docker pull mysql:5.7(這個版本我已經在docker hub查過有這個版本,不能隨便寫)
docker rmi -f 鏡像ID #洗掉鏡像
docker rmi -f 鏡像ID #洗掉指定鏡像
docker rmi -f 鏡像ID 鏡像ID 鏡像ID #洗掉多個鏡像
docker rmi -f $(docker images -aq) #洗掉全部的鏡像
三、容器命令
docker run [可選引數] 鏡像ID #新建容器并啟動
#引數說明(常用)
--name="Name" #容器名稱,如:tomcat01,tomcat02 用來區分容器
-d #后臺方式運行
-it #使用互動方式運行,進入容器查看內容
-p #指定容器的埠,默認什么都不寫的情況下,隨機指定埠
主機埠:容器埠(常用) eg:-p 8080:8080
eg:
[root@localhost ~]# docker run -it --name="mysql_01" mysql /bin/bash
root@39b60d099519:/# ls
bin dev entrypoint.sh home lib64 mnt proc run srv tmp var
boot docker-entrypoint-initdb.d etc lib media opt root sbin sys usr
root@39b60d099519:/#
#從容器內退回主機
exit #容器停止并退出
Ctrl+P+Q #容器不停止退出
#洗掉容器
docker rm 容器ID #洗掉指定的容器,不能洗掉正在運行的容器,如果要強制洗掉,則 rm -f
docker rm -f $(docker ps -aq) #洗掉所有的容器
docker ps -aq|xargs docker rm #洗掉所有的容器
#啟動和停止容器的操作
docker start 容器ID #啟動容器
docker restart 容器ID #重啟容器
docker stop 容器ID #停止當前正在運行的容器
docker kill 容器ID #強制停止當前容器
docker ps
四、其他常用命令
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/352075.html
標籤:其他
上一篇:docker中konga的安裝
