一、帮助命令

  1. docker version # 查看docker 版本信息
  2. docker info # 查看docker 系统信息
  3. docker 命令 --help # 查看docker 常用命令的使用方法

二、镜像命令

2.1 docker images 命令

(1)docker images 查看主机上的镜像

  1. [root@localhost ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
  4. [root@localhost ~]#

(2)docker images —help 查看 docker images的帮助信息

  1. [root@localhost ~]# docker images --help
  2. Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
  3. List images
  4. Options:
  5. -a, --all Show all images (default hides intermediate images)
  6. --digests Show digests
  7. -f, --filter filter Filter output based on conditions provided
  8. --format string Pretty-print images using a Go template
  9. --no-trunc Don't truncate output
  10. -q, --quiet Only show image IDs
  11. [root@localhost ~]#

(3)docker images -a 查看主机上的所有镜像

  1. [root@localhost ~]# docker images -a
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
  4. [root@localhost ~]#

(4)docker images -q 只显示docker镜像的id

  1. [root@localhost ~]# docker images -q
  2. feb5d9fea6a5
  3. [root@localhost ~]#

2.2 docker search 镜像名称 命令

(1)docker search 镜像名称,搜索镜像

  1. [root@localhost ~]# docker search mysql
  2. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  3. mysql MySQL is a widely used, open-source relation 11516 [OK]
  4. mariadb MariaDB Server is a high performing open sou 4369 [OK]
  5. mysql/mysql-server Optimized MySQL Server Docker images. Create 851 [OK]
  6. percona Percona Server is a fork of the MySQL relati 558 [OK]
  7. phpmyadmin phpMyAdmin - A web interface for MySQL and M 339 [OK]
  8. centos/mysql-57-centos7 MySQL 5.7 SQL database server 91
  9. mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr 88
  10. centurylink/mysql Image containing mysql. Optimized to be link 59 [OK]
  11. databack/mysql-backup Back up mysql databases to... anywhere! 51
  12. prom/mysqld-exporter 42 [OK]
  13. deitch/mysql-backup REPLACED! Please use http://hub.docker.com/r 41 [OK]
  14. tutum/mysql Base docker image to run a MySQL database se 35
  15. linuxserver/mysql A Mysql container, brought to you by LinuxSe 31
  16. schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup 31 [OK]
  17. mysql/mysql-router MySQL Router provides transparent routing be 23
  18. centos/mysql-56-centos7 MySQL 5.6 SQL database server 20
  19. arey/mysql-client Run a MySQL client from a docker container 18 [OK]
  20. fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas 16 [OK]
  21. openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image 6
  22. idoall/mysql MySQL is a widely used, open-source relation 3 [OK]
  23. devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici 3
  24. jelastic/mysql An image of the MySQL database server mainta 2
  25. ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK]
  26. widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl 1 [OK]
  27. centos/mysql-80-centos7 MySQL 8.0 SQL database server 1
  28. [root@localhost ~]#

(2)docker search —help 查看docker search 命令的帮助信息

  1. [root@localhost ~]# docker search --help
  2. Usage: docker search [OPTIONS] TERM
  3. Search the Docker Hub for images
  4. Options:
  5. -f, --filter filter Filter output based on conditions provided
  6. --format string Pretty-print search using a Go template
  7. --limit int Max number of search results (default 25)
  8. --no-trunc Don't truncate output
  9. [root@localhost ~]#

(3)docker search —filter 过滤条件 根据过滤条件搜索镜像
如下为搜索收藏数大于等于3000的mysql镜像

  1. [root@localhost ~]# docker search mysql --filter stars=3000
  2. NAME DESCRIPTION STARS OFFICIAL AUTOMATED
  3. mysql MySQL is a widely used, open-source relation 11516 [OK]
  4. mariadb MariaDB Server is a high performing open sou 4369 [OK]
  5. [root@localhost ~]#

2.3 docker pull 命令

(1) docker pull 镜像名称 下载最新版的镜像
如下为下载最新版的mysql镜像

  1. [root@localhost ~]# docker pull mysql
  2. Using default tag: latest
  3. latest: Pulling from library/mysql
  4. 07aded7c29c6: Pull complete
  5. f68b8cbd22de: Pull complete
  6. 30c1754a28c4: Pull complete
  7. 1b7cb4d6fe05: Pull complete
  8. 79a41dc56b9a: Pull complete
  9. 00a75e3842fb: Pull complete
  10. b36a6919c217: Pull complete
  11. 635b0b84d686: Pull complete
  12. 6d24c7242d02: Pull complete
  13. 5be6c5edf16f: Pull complete
  14. cb35eac1242c: Pull complete
  15. a573d4e1c407: Pull complete
  16. Digest: sha256:4fcf5df6c46c80db19675a5c067e737c1bc8b0e78e94e816a778ae2c6577213d
  17. Status: Downloaded newer image for mysql:latest
  18. docker.io/library/mysql:latest
  19. [root@localhost ~]#

如下,可以看到显示已经下载完成的mysql镜像版本为latest

  1. [root@localhost ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. mysql latest 2fe463762680 11 days ago 514MB
  4. hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
  5. [root@localhost ~]#

(2)docker pull 镜像名称:tag 下载指定版本的镜像
如下为指定下载5.7版本的mysql

  1. [root@localhost ~]# docker pull mysql:5.7
  2. 5.7: Pulling from library/mysql
  3. 07aded7c29c6: Already exists
  4. f68b8cbd22de: Already exists
  5. 30c1754a28c4: Already exists
  6. 1b7cb4d6fe05: Already exists
  7. 79a41dc56b9a: Already exists
  8. 00a75e3842fb: Already exists
  9. b36a6919c217: Already exists
  10. 5e11fe494f45: Pull complete
  11. 9c7de1f889a7: Pull complete
  12. cf6a13d05a76: Pull complete
  13. fc5aa81f393a: Pull complete
  14. Digest: sha256:360c7488c2b5d112804a74cd272d1070d264eef4812d9a9cc6b8ed68c3546189
  15. Status: Downloaded newer image for mysql:5.7
  16. docker.io/library/mysql:5.7
  17. [root@localhost ~]#

如下,可以看到本地已经存在5.7版本的mysql镜像

  1. [root@localhost ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. mysql 5.7 9f35042c6a98 11 days ago 448MB
  4. mysql latest 2fe463762680 11 days ago 514MB
  5. hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
  6. [root@localhost ~]#

2.4 docker rmi 删除镜像

(1)docker rmi 镜像id 根据镜像id删除镜像
如下为根据镜像id删除5.7版的mysql镜像的操作

  1. [root@localhost ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. mysql 5.7 9f35042c6a98 11 days ago 448MB
  4. mysql latest 2fe463762680 11 days ago 514MB
  5. hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
  6. [root@localhost ~]# docker rmi 9f35042c6a98
  7. Untagged: mysql:5.7
  8. Untagged: mysql@sha256:360c7488c2b5d112804a74cd272d1070d264eef4812d9a9cc6b8ed68c3546189
  9. Deleted: sha256:9f35042c6a98363147ae456147643a3d14c484640f13f4ab207cf2c296839baf
  10. Deleted: sha256:69a5732b5b989ff688326db6354b0f50165a71cfe7579b285054b561fb3c5143
  11. Deleted: sha256:448b1f9cb8f126363f0e809e0e450c493ca1e725715127a258c5346fcae7cd8a
  12. Deleted: sha256:4064542818b4bf92f293da870d3ea1413a20d0c1a83f72917c50986880255338
  13. Deleted: sha256:8ca7f5e08bac7aa39cf9b8b79bf40669373b9aed45ec76eb0fa55109350b6672
  14. [root@localhost ~]# docker images
  15. REPOSITORY TAG IMAGE ID CREATED SIZE
  16. mysql latest 2fe463762680 11 days ago 514MB
  17. hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
  18. [root@localhost ~]#

(2)docker rmi -f 镜像id 根据镜像id强制删除镜像
一般常用加 -f 的方式删除

  1. [root@localhost ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. mysql 5.7 9f35042c6a98 11 days ago 448MB
  4. mysql latest 2fe463762680 11 days ago 514MB
  5. hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
  6. [root@localhost ~]# docker rmi -f 2fe463762680
  7. Untagged: mysql:latest
  8. Untagged: mysql@sha256:4fcf5df6c46c80db19675a5c067e737c1bc8b0e78e94e816a778ae2c6577213d
  9. Deleted: sha256:2fe4637626805dc6df98d3dc17fa9b5035802dcbd3832ead172e3145cd7c07c2
  10. Deleted: sha256:e00bdaa10222919253848d65585d53278a2f494ce8c6a445e5af0ebfe239b3b5
  11. Deleted: sha256:83411745a5928b2a3c2b6510363218fb390329f824e04bab13573e7a752afd50
  12. Deleted: sha256:e8e521a71a92aad623b250b0a192a22d54ad8bbeb943f7111026041dce20d94f
  13. Deleted: sha256:024ee0ef78b28663bc07df401ae3a258ae012bd5f37c2960cf638ab4bc04fafd
  14. Deleted: sha256:597139ec344c8cb622127618ae21345b96dd23e36b5d04b071a3fd92d207a2c0
  15. [root@localhost ~]# docker images
  16. REPOSITORY TAG IMAGE ID CREATED SIZE
  17. mysql 5.7 9f35042c6a98 11 days ago 448MB
  18. hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
  19. [root@localhost ~]#

(3)docker rmi -f $(docker images -aq) 删除所有镜像

  1. [root@localhost ~]# docker images
  2. REPOSITORY TAG IMAGE ID CREATED SIZE
  3. mysql 5.7 9f35042c6a98 11 days ago 448MB
  4. mysql latest 2fe463762680 11 days ago 514MB
  5. hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
  6. [root@localhost ~]# docker rmi -f $(docker images -aq)
  7. Untagged: mysql:5.7
  8. Untagged: mysql@sha256:360c7488c2b5d112804a74cd272d1070d264eef4812d9a9cc6b8ed68c3546189
  9. Deleted: sha256:9f35042c6a98363147ae456147643a3d14c484640f13f4ab207cf2c296839baf
  10. Deleted: sha256:69a5732b5b989ff688326db6354b0f50165a71cfe7579b285054b561fb3c5143
  11. Deleted: sha256:448b1f9cb8f126363f0e809e0e450c493ca1e725715127a258c5346fcae7cd8a
  12. Deleted: sha256:4064542818b4bf92f293da870d3ea1413a20d0c1a83f72917c50986880255338
  13. Deleted: sha256:8ca7f5e08bac7aa39cf9b8b79bf40669373b9aed45ec76eb0fa55109350b6672
  14. Untagged: mysql:latest
  15. Untagged: mysql@sha256:4fcf5df6c46c80db19675a5c067e737c1bc8b0e78e94e816a778ae2c6577213d
  16. Deleted: sha256:2fe4637626805dc6df98d3dc17fa9b5035802dcbd3832ead172e3145cd7c07c2
  17. Deleted: sha256:e00bdaa10222919253848d65585d53278a2f494ce8c6a445e5af0ebfe239b3b5
  18. Deleted: sha256:83411745a5928b2a3c2b6510363218fb390329f824e04bab13573e7a752afd50
  19. Deleted: sha256:e8e521a71a92aad623b250b0a192a22d54ad8bbeb943f7111026041dce20d94f
  20. Deleted: sha256:024ee0ef78b28663bc07df401ae3a258ae012bd5f37c2960cf638ab4bc04fafd
  21. Deleted: sha256:597139ec344c8cb622127618ae21345b96dd23e36b5d04b071a3fd92d207a2c0
  22. Deleted: sha256:28909b85bd680fc47702edb647a06183ae5f3e3020f44ec0d125bf75936aa923
  23. Deleted: sha256:4e007ef1e2a3e1e0ffb7c0ad8c9ea86d3d3064e360eaa16e7c8e10f514f68339
  24. Deleted: sha256:b01d7bbbd5c0e2e5ae10de108aba7cd2d059bdd890814931f6192c97fc8aa984
  25. Deleted: sha256:d98a368fc2299bfa2c34cc634fa9ca34bf1d035e0cca02e8c9f0a07700f18103
  26. Deleted: sha256:95968d83b58ae5eec87e4c9027baa628d0e24e4acebea5d0f35eb1b957dd4672
  27. Deleted: sha256:425adb901baf7d6686271d2ce9d42b8ca67e53cffa1bc05622fd0226ae40e9d8
  28. Deleted: sha256:476baebdfbf7a68c50e979971fcd47d799d1b194bcf1f03c1c979e9262bcd364
  29. Untagged: hello-world:latest
  30. Untagged: hello-world@sha256:9ade9cc2e26189a19c2e8854b9c8f1e14829b51c55a630ee675a5a9540ef6ccf
  31. Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
  32. [root@localhost ~]# docker images
  33. REPOSITORY TAG IMAGE ID CREATED SIZE
  34. [root@localhost ~]#