前言
本篇是零基礎學Docker系列的第二篇文章,在上一篇文章中👉一文帶你快速了解并上手Docker已經為大家講解了一些什么是Docker,如何安裝使用Docker的內容,以及對Docker與虛擬機技術的一個簡單對比做了一些說明,本篇我們將趁熱打鐵,需要完成的任務如下:
- 掌握Docker的常用命令,包含但不限于鏡像命令,容器命令,以及一些常用的其他命令
- 學會使用官方檔案查找對應的命令說明
- 學會使用幫助命令來查找對應的命令說明

申明
部分內容來源于網上資源,如若侵犯到您的權益,請聯系作者第一時間洗掉
Docker常用命令
Docker的官方檔案非常的詳細,關于所有的命令列使用說明/規范,可以參考 https://docs.docker.com/reference/

我們以docker images命令為例,可以發現在官方檔案上有非常詳細的說明,對于每種命令的介紹說明,用法,拓展使用,引數選項,例子…都非常的齊全,

另外我們也可以通過幫助命令在命令列中讓我們了解到不同的命令使用,
1、幫助命令
docker version #顯示docker的版本資訊,
docker info #顯示docker的系統資訊,包括鏡像和容器的數量
docker 命令 --help #幫助命令
2、鏡像命令
docker images #查看所有本地主機上的鏡像 可以使用docker image ls代替
docker search #搜索鏡像
docker pull #下載鏡像 docker image pull
docker rmi #洗掉鏡像 docker image rm
docker images 查看所有本地的主機上的鏡像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
portainer/portainer latest 62771b0b9b09 3 months ago 79.1MB
hello-world latest bf756fb1ae65 10 months ago 13.3kB
# 解釋
#REPOSITORY # 鏡像的倉庫源
#TAG # 鏡像的標簽(版本) ---lastest 表示最新版本
#IMAGE ID # 鏡像的id
#CREATED # 鏡像的創建時間
#SIZE # 鏡像的大小
# 可選項
Options:
-a, --all Show all images (default hides intermediate images) #列出所有鏡像
-q, --quiet Only show numeric IDs # 只顯示鏡像的id
[root@localhost ~]# docker images -a #列出所有鏡像詳細資訊
REPOSITORY TAG IMAGE ID CREATED SIZE
portainer/portainer latest 62771b0b9b09 3 months ago 79.1MB
hello-world latest bf756fb1ae65 10 months ago 13.3kB
[root@localhost ~]# docker images -aq #列出所有鏡像的id
62771b0b9b09
bf756fb1ae65
docker search 搜索鏡像
[root@localhost ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 10136 [OK]
mariadb MariaDB is a community-developed fork of MyS… 3733 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 741 [OK]
percona Percona Server is a fork of the MySQL relati… 511 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 84
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 78
centurylink/mysql Image containing mysql. Optimized to be link… 60 [OK]
bitnami/mysql Bitnami MySQL Docker Image 46 [OK]
deitch/mysql-backup REPLACED! Please use http://hub.docker.com/r… 41 [OK]
tutum/mysql Base docker image to run a MySQL database se… 35
prom/mysqld-exporter 31 [OK]
databack/mysql-backup Back up mysql databases to... anywhere! 31
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 29 [OK]
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 26
centos/mysql-56-centos7 MySQL 5.6 SQL database server 20
circleci/mysql MySQL is a widely used, open-source relation… 19
mysql/mysql-router MySQL Router provides transparent routing be… 17
arey/mysql-client Run a MySQL client from a docker container 15 [OK]
fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas… 10 [OK]
yloeffler/mysql-backup This image runs mysqldump to backup data usi… 7 [OK]
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici… 3
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK]
jelastic/mysql An image of the MySQL database server mainta… 1
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 1 [OK]
# 可選項,通過搜索來過濾,例如想要實作搜索出來的鏡像收藏STARS數量大于3000的
# --filter=STARS=3000
Options:
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print search using a Go template
--limit int Max number of search results (default 25)
--no-trunc Don't truncate output
[root@localhost ~]# docker search mysql --filter=STARS=5000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 10136 [OK]
docker pull 下載鏡像
能夠搜索之后,我們就可以去下載鏡像,
# 下載鏡像 docker pull 鏡像名[:tag]
[root@localhost ~]# docker pull mysql
Using default tag: latest #如果不寫tag,默認就是latest
latest: Pulling from library/mysql #分層下載: docker image 的核心 聯合檔案系統
bb79b6b2107f: Pull complete
49e22f6fb9f7: Pull complete
842b1255668c: Pull complete
9f48d1f43000: Pull complete
c693f0615bce: Pull complete
8a621b9dbed2: Pull complete
0807d32aef13: Pull complete
a56aca0feb17: Pull complete
de9d45fd0f07: Pull complete
1d68a49161cc: Pull complete
d16d318b774e: Pull complete
49e112c55976: Pull complete
Digest: sha256:8c17271df53ee3b843d6e16d46cff13f22c9c04d6982eb15a9a47bd5c9ac7e2d # 簽名防偽
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest #真實地址
# 等價于
docker pull mysql
docker pull docker.io/library/mysql:latest
# 指定版本進行下載
[root@localhost ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
bb79b6b2107f: Already exists
49e22f6fb9f7: Already exists
842b1255668c: Already exists
9f48d1f43000: Already exists
c693f0615bce: Already exists
8a621b9dbed2: Already exists
0807d32aef13: Already exists
f15d42f48bd9: Pull complete
098ceecc0c8d: Pull complete
b6fead9737bc: Pull complete
351d223d3d76: Pull complete
Digest: sha256:4d2b34e99c14edb99cdd95ddad4d9aa7ea3f2c4405ff0c3509a29dc40bcb10ef
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
可以發現存在共用鏡像的時候,docker就不會去重復下載,極大的節省了記憶體,
等待下載完畢,我們再去查看主機上的docker的鏡像檔案,

可以發現下載的鏡像都比較的大,這個時候我們就可以去考慮洗掉一些鏡像,
docker rmi 洗掉鏡像
docker rmi -f 鏡像id #洗掉指定的鏡像
docker rmi -f 鏡像id 鏡像id 鏡像id # 洗掉多個鏡像
docker rmi -f $(docker images -aq) # 騷操作:洗掉全部的鏡像,遞回洗掉
[root@localhost ~]# docker rmi -f 1b12f2e9257b
Untagged: mysql:5.7
Untagged: mysql@sha256:4d2b34e99c14edb99cdd95ddad4d9aa7ea3f2c4405ff0c3509a29dc40bcb10ef
Deleted: sha256:1b12f2e9257be96da5c075f186dc371b18442b0f9281728ac64c9a69c6e0e264
Deleted: sha256:b21d85dcc43f7db4e532c3ca07e5adbc1e02beb37646b7079217ea2b1922af91
Deleted: sha256:603c9faa831d58a3f60eb377cd6246a281a97b906406a92bf3452726a6f15b69
Deleted: sha256:2d927a6eb4cc26ba5454193a3f4abf503b6cea710293d4f0e6d061c08578b687
Deleted: sha256:b96c2c2176ca7b5223469ad39c9e17509505233dd81030878bc12b03074baef4
...
3、容器命令
說明:我們有了鏡像,才可以創建容器,接下來,我們將下載一個centos鏡像來測驗學習,
[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
3c72a8ed6814: Pull complete
Digest: sha256:76d24f3ba3317fa945743bb3746fbaf3a0b752f10b10376960de01da70685fbd
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
新建容器并啟動
docker run [可選引數] image
# 引數說明
--name = “Name” 容器名字 tomcat01 tomcat02,用于區分容器
-d 后臺方式運行
-it 使用互動式運行,進入容器查看內容
-p 指定容器的埠 -p 8080:8080
-p ip:主機埠:容器埠
-p 主機埠:容器埠(常用)
-p 容器埠
(不加-p,直接加容器埠也可以)
-P(大寫) 隨機指定埠
# 測驗,啟動并進入容器
[root@localhost /]# docker run -it centos /bin/bash
[root@e1ac54cd636a /]# ls # 查看容器內的centos:基礎版本,很多命令都是不完整的!
bin etc lib lost+found mnt proc run srv tmp var
dev home lib64 media opt root sbin sys usr
# 從容器中退回主機
[root@e1ac54cd636a /]# exit
exit
[root@localhost /]# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
列出所有運行的容器
# docker ps 命令 列出當前正在運行的容器
-a ,--all #列出當前正在運行的容器 + 帶出歷史運行過的容器
-n=?, --last int #列出最近創建的?個容器 ?為1則只列出最近創建的一個容器,為2則列出2個
-q, --quiet #只列出容器的編號
[root@localhost /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd5ea781f128 portainer/portainer "/portainer" 14 hours ago Up 14 hours 0.0.0.0:8088->9000/tcp charming_volhard
[root@localhost /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e1ac54cd636a centos "/bin/bash" 5 minutes ago Exited (0) 4 minutes ago epic_engelbart
fd5ea781f128 portainer/portainer "/portainer" 14 hours ago Up 14 hours 0.0.0.0:8088->9000/tcp charming_volhard
ec6397ed87c8 bf756fb1ae65 "/hello" 17 hours ago Exited (0) 17 hours ago ecstatic_mestorf
1db69ebb5c34 bf756fb1ae65 "/hello" 17 hours ago Exited (0) 17 hours ago eager_lamport
a40257529012 bf756fb1ae65 "/hello" 22 hours ago Exited (0) 22 hours ago crazy_greider
退出容器
exit # 容器直接退出
ctrl +P +Q # 容器不停止退出 -- 注意: 這個是很有用的操作
洗掉容器
docker rm 容器id #洗掉指定的容器,不能洗掉正在運行的容器,如果要強制洗掉 rm -rf
docker rm -f $(docker ps -aq) #洗掉所有的容器
docker ps -a -q|xargs docker rm #洗掉所有的容器
啟動和停止容器的操作
docker start 容器id #啟動容器
docker restart 容器id #重啟容器
docker stop 容器id #停止當前正在運行的容器
docker kill 容器id #強制停止當前容器
4、常用的其他命令
后臺啟動容器
# 命令 docker run -d 鏡像名
[root@localhost /]# docker run -d centos
c792b680e6250ba7c3892de771a7328baa936518cc35cd47eda0634419228dba
[root@localhost /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fd5ea781f128 portainer/portainer "/portainer" 15 hours ago Up 15 hours 0.0.0.0:8088->9000/tcp charming_volhard
# 問題:docker ps:發現 centos 停止了
# 常見的坑:docker容器使用后臺運行,就必須要有一個前臺行程,docker發現沒有應用,就會自動停止
查看日志
docker logs --help
Options:
--details Show extra details provided to logs
* -f, --follow Follow log output
--since string Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
* --tail string Number of lines to show from the end of the logs (default "all")
* -t, --timestamps Show timestamps
--until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
? ~ docker run -d centos /bin/sh -c "while true;do echo 6666;sleep 1;done" #模擬日志
#顯示日志
-tf #顯示日志資訊(一直更新)
--tail number #需要顯示日志條數
docker logs -t --tail n 容器id # 查看n行日志
docker logs -ft 容器id # 顯示所有日志日志
# 運行centos 容器
[root@localhost /]# docker run -it centos /bin/bash
# 查看所有的容器運行情況
[root@localhost /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
529d488fbb4b centos "/bin/bash" 50 seconds ago Up 50 seconds gracious_blackburn
4a0ba742b224 centos "/bin/bash" 20 minutes ago Exited (130) 19 minutes ago exciting_perlman
c792b680e625 centos "/bin/bash" 26 minutes ago Exited (0) 26 minutes ago nice_pike
# 根據容器id,查詢最近的10條日志
[root@localhost /]# docker logs -f -t --tail 10 529d488fbb4b
#因為我們centos的容器暫時還沒有進行任何的操作,所以可能日志顯示為空
# 我們可以自己撰寫一段shell腳本
[root@localhost /]# docker run -d centos /bin/sh -c "while true;do echo 6666;sleep 1;done"
# 再次查看日志
[root@localhost /]# docker logs -f -t --tail 10 492b2410a53f
2020-11-08T05:54:01.436376750Z 6666
2020-11-08T05:54:02.438071320Z 6666
2020-11-08T05:54:03.440787888Z 6666
2020-11-08T05:54:04.443239744Z 6666
...
# 就可以觀察到有源源不斷的日志產生了
查看容器中行程資訊
# 命令 docker top 容器id
[root@localhost /]# docker top 9a1f7b30a10a
UID PID PPID C STIME TTY TIME CMD
root 45074 45058 0 14:03 ? 00:00:00 /bin/bash
查看鏡像的元資料資訊
# 命令
docker inspect 容器id
# 測驗
[root@localhost /]# docker inspect 9a1f7b30a10a
[
{
"Id": "9a1f7b30a10a33a36b7649e8f0992247c7767fccc2d253dfdf7a42b0c4cb1220",
"Created": "2020-11-08T06:03:48.598473909Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 45074,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-11-08T06:03:48.796392054Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:0d120b6ccaa8c5e149176798b3501d4dd1885f961922497cd0abef155c869566",
"ResolvConfPath": "/var/lib/docker/containers/9a1f7b30a10a33a36b7649e8f0992247c7767fccc2d253dfdf7a42b0c4cb1220/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/9a1f7b30a10a33a36b7649e8f0992247c7767fccc2d253dfdf7a42b0c4cb1220/hostname",
"HostsPath": "/var/lib/docker/containers/9a1f7b30a10a33a36b7649e8f0992247c7767fccc2d253dfdf7a42b0c4cb1220/hosts",
"LogPath": "/var/lib/docker/containers/9a1f7b30a10a33a36b7649e8f0992247c7767fccc2d253dfdf7a42b0c4cb1220/9a1f7b30a10a33a36b7649e8f0992247c7767fccc2d253dfdf7a42b0c4cb1220-json.log",
"Name": "/jolly_mayer",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/e9101448258930021351001b2ad30349f485f11800752a56c174cbf7ca0e0057-init/diff:/var/lib/docker/overlay2/2ffe0b620bf852329f5b2c405efb84cd6bbb1abbd75879276b4bed0e1962effc/diff",
"MergedDir": "/var/lib/docker/overlay2/e9101448258930021351001b2ad30349f485f11800752a56c174cbf7ca0e0057/merged",
"UpperDir": "/var/lib/docker/overlay2/e9101448258930021351001b2ad30349f485f11800752a56c174cbf7ca0e0057/diff",
"WorkDir": "/var/lib/docker/overlay2/e9101448258930021351001b2ad30349f485f11800752a56c174cbf7ca0e0057/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "9a1f7b30a10a",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Image": "centos",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20200809",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "f125e682faaca30a5ff2ea78298b6a63aa4b416de1a4150dc2271de55bb2bec5",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/f125e682faac",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "d49e14b7c195c2bb3d2ccad715cec0410d6b47e81fdec609296ac6ee84a47fb5",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "97d11e1f759394b549127015587527c5590965c6a66d0b1a5314dcf3b2ba626a",
"EndpointID": "d49e14b7c195c2bb3d2ccad715cec0410d6b47e81fdec609296ac6ee84a47fb5",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
進入當前正在運行的容器
# 方式一:
docker exec -it 容器id bashshell
# 測驗
[root@localhost /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a1f7b30a10a centos "/bin/bash" 16 minutes ago Up 15 minutes jolly_mayer
[root@localhost /]# docker exec -it 9a1f7b30a10a /bin/bash
[root@9a1f7b30a10a /]# ps -df
UID PID PPID C STIME TTY TIME CMD
root 32 19 0 06:19 pts/1 00:00:00 ps -df
[root@9a1f7b30a10a /]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 06:03 pts/0 00:00:00 /bin/bash
root 19 0 0 06:18 pts/1 00:00:00 /bin/bash
root 33 19 0 06:19 pts/1 00:00:00 ps -ef
# 方式二:
docker attach 容器id
# 測驗
[root@localhost /]# docker attach 9a1f7b30a10a
正在執行代碼....
# 命令對比
# docker exec # 進入容器后開啟一個新的終端,可以在里面操作(常用)
# docker attach # 進入容器正在執行的終端,不會啟動新的行程
從容器內拷貝到主機上
docker cp 容器id:容器內路徑 主機目的路徑
# 進入正在運行的centos容器內部
[root@localhost /]# docker attach 9a1f7b30a10a
# 新建一個檔案,并退出結束容器
[root@9a1f7b30a10a /]# touch test.java
[root@9a1f7b30a10a /]# exit
exit
# 查看此時正運行的容器
[root@localhost /]# docker ps
CONTAINER ID IMAGE COMMAND CREATED S
# 查看所有的容器串列 ,只要容器還在,容器內的資料就丟不了 TATUS PORTS NAMES
[root@localhost /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a1f7b30a10a centos "/bin/bash" 46 minutes ago
# 執行拷貝命令,將容器中的檔案拷貝至本機
[root@localhost /]# docker cp 9a1f7b30a10a:/test.java /home
# 可以在本地查看到從docker容器中拷貝的檔案
[root@localhost /]# ls /home
test.java
這里講的拷貝實際上是一個拷貝的程序,未來我們使用 -v 卷的技術,可以實作,容器內與本地檔案的自動同步,
小結

Docker的命令實際上非常多,我們最好整理一份命令列大全,今后需要進行查詢的話,就可以從中快速獲取,
attach Attach local standard input, output, and error streams to a running container
#當前shell下 attach連接指定運行的鏡像
build Build an image from a Dockerfile # 通過Dockerfile定制鏡像
commit Create a new image from a container's changes #提交當前容器為新的鏡像
cp Copy files/folders between a container and the local filesystem #拷貝檔案
create Create a new container #創建一個新的容器
diff Inspect changes to files or directories on a container's filesystem #查看docker容器的變化
events Get real time events from the server # 從服務獲取容器實時時間
exec Run a command in a running container # 在已存在的容器上運行命令
export Export a container's filesystem as a tar archive #匯出容器檔案系統作為一個tar歸檔檔案[對應import]
history Show the history of an image # 展示一個鏡像形成歷史
images List images #列出系統當前的鏡像
import Import the contents from a tarball to create a filesystem image #從tar包中匯入內容創建一個檔案系統鏡像
info Display system-wide information # 顯示系統相關資訊
inspect Return low-level information on Docker objects #查看容器詳細資訊
kill Kill one or more running containers # kill 指定 docker容器
load Load an image from a tar archive or STDIN # 從一個tar包或標準輸入中加載一個鏡像[對應save]
login Log in to a Docker registry # 注冊或者登陸一下 docker 源服務器
logout Log out from a Docker registry # 從當前 Docker registry 退出
logs Fetch the logs of a container # 輸出當前容器日志資訊
pause Pause all processes within one or more containers # 輸出當前容器日志資訊
port List port mappings or a specific mapping for the container # 查看映射埠對應的容器內部源埠
ps List containers # 列出容器串列
pull Pull an image or a repository from a registry # 從 docker 鏡像源服務器抽取指定鏡像或者鏡像庫
push Push an image or a repository to a registry # 推送指定鏡像或者庫鏡像至docker源服務器
rename Rename a container # 重新命名容器
restart Restart one or more containers # 重啟運行的容器
rm Remove one or more containers # 移除一個或者多個容器
rmi Remove one or more images # 移除一個或者多個鏡像[無容器使用該鏡像才可以洗掉,否則需洗掉相關容器才可繼續或 -f 強制洗掉]
run Run a command in a new container # 創建一個新的容器并運行一個命令
save Save one or more images to a tar archive (streamed to STDOUT by default) # 保存一個鏡像為一個 tar包[對應 load]
search Search the Docker Hub for images # 在 docker hub 中搜索鏡像
start Start one or more stopped containers # 啟動容器
stop Stop one or more running containers # 停止容器
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE # 給源中鏡像打標簽
top Display the running processes of a container # 查看容器中運行的行程資訊
unpause Unpause all processes within one or more containers # 取消暫停容器
update Update configuration of one or more containers # 更新一個或多個容器的配置
version Show the Docker version information # 查看 docker 版本號
wait Block until one or more containers stop, then print their exit codes # 截取容器停止時的退出狀態值
彩蛋
有幸收藏過一份尚硅谷周陽老師制作的Docker思維導圖,想獲取源檔案的朋友,可以在公眾號【猿人菌】后臺回復“Docker思維導圖”獲取喲~

下期預告
下一篇文章將為大家帶來關于在Docker中部署Nginx,Tomcat,ES+Kibana 的教程…敬請期待!
一鍵三連,養成習慣~
文章持續更新,可以微信搜一搜「 猿人菌 」第一時間閱讀,思維導圖,大資料書籍,大資料高頻面試題,海量一線大廠面經…期待您的關注!
CSDN認證博客專家
CSDN博客專家
大資料學者
追夢人
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/208756.html
標籤:其他
上一篇:用例子理解遞回
