【原文链接】
一、帮助命令
docker version # 查看docker 版本信息
docker info # 查看docker 系统信息
docker 命令 --help # 查看docker 常用命令的使用方法
二、镜像命令
2.1 docker images 命令
(1)docker images 查看主机上的镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
[root@localhost ~]#
(2)docker images --help 查看 docker images的帮助信息
[root@localhost ~]# docker images --help
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options:
-a, --all Show all images (default hides intermediate images)
--digests Show digests
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print images using a Go template
--no-trunc Don't truncate output
-q, --quiet Only show image IDs
[root@localhost ~]#
(3)docker images -a 查看主机上的所有镜像
[root@localhost ~]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
[root@localhost ~]#
(4)docker images -q 只显示docker镜像的id
[root@localhost ~]# docker images -q
feb5d9fea6a5
[root@localhost ~]#
2.2 docker search 镜像名称 命令
(1)docker search 镜像名称,搜索镜像
[root@localhost ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11516 [OK]
mariadb MariaDB Server is a high performing open sou… 4369 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 851 [OK]
percona Percona Server is a fork of the MySQL relati… 558 [OK]
phpmyadmin phpMyAdmin - A web interface for MySQL and M… 339 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 91
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 88
centurylink/mysql Image containing mysql. Optimized to be link… 59 [OK]
databack/mysql-backup Back up mysql databases to... anywhere! 51
prom/mysqld-exporter 42 [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
linuxserver/mysql A Mysql container, brought to you by LinuxSe… 31
schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 31 [OK]
mysql/mysql-router MySQL Router provides transparent routing be… 23
centos/mysql-56-centos7 MySQL 5.6 SQL database server 20
arey/mysql-client Run a MySQL client from a docker container 18 [OK]
fradelg/mysql-cron-backup MySQL/MariaDB database backup using cron tas… 16 [OK]
openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6
idoall/mysql MySQL is a widely used, open-source relation… 3 [OK]
devilbox/mysql Retagged MySQL, MariaDB and PerconaDB offici… 3
jelastic/mysql An image of the MySQL database server mainta… 2
ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 2 [OK]
widdpim/mysql-client Dockerized MySQL Client (5.7) including Curl… 1 [OK]
centos/mysql-80-centos7 MySQL 8.0 SQL database server 1
[root@localhost ~]#
(2)docker search --help 查看docker search 命令的帮助信息
[root@localhost ~]# docker search --help
Usage: docker search [OPTIONS] TERM
Search the Docker Hub for images
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 ~]#
(3)docker search --filter 过滤条件 根据过滤条件搜索镜像
如下为搜索收藏数大于等于3000的mysql镜像
[root@localhost ~]# docker search mysql --filter stars=3000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11516 [OK]
mariadb MariaDB Server is a high performing open sou… 4369 [OK]
[root@localhost ~]#
2.3 docker pull 命令
(1) docker pull 镜像名称 下载最新版的镜像
如下为下载最新版的mysql镜像
[root@localhost ~]# docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
07aded7c29c6: Pull complete
f68b8cbd22de: Pull complete
30c1754a28c4: Pull complete
1b7cb4d6fe05: Pull complete
79a41dc56b9a: Pull complete
00a75e3842fb: Pull complete
b36a6919c217: Pull complete
635b0b84d686: Pull complete
6d24c7242d02: Pull complete
5be6c5edf16f: Pull complete
cb35eac1242c: Pull complete
a573d4e1c407: Pull complete
Digest: sha256:4fcf5df6c46c80db19675a5c067e737c1bc8b0e78e94e816a778ae2c6577213d
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
[root@localhost ~]#
如下,可以看到显示已经下载完成的mysql镜像版本为latest
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 2fe463762680 11 days ago 514MB
hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
[root@localhost ~]#
(2)docker pull 镜像名称:tag 下载指定版本的镜像
如下为指定下载5.7版本的mysql
[root@localhost ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
07aded7c29c6: Already exists
f68b8cbd22de: Already exists
30c1754a28c4: Already exists
1b7cb4d6fe05: Already exists
79a41dc56b9a: Already exists
00a75e3842fb: Already exists
b36a6919c217: Already exists
5e11fe494f45: Pull complete
9c7de1f889a7: Pull complete
cf6a13d05a76: Pull complete
fc5aa81f393a: Pull complete
Digest: sha256:360c7488c2b5d112804a74cd272d1070d264eef4812d9a9cc6b8ed68c3546189
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
[root@localhost ~]#
如下,可以看到本地已经存在5.7版本的mysql镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 9f35042c6a98 11 days ago 448MB
mysql latest 2fe463762680 11 days ago 514MB
hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
[root@localhost ~]#
2.4 docker rmi 删除镜像
(1)docker rmi 镜像id 根据镜像id删除镜像
如下为根据镜像id删除5.7版的mysql镜像的操作
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 9f35042c6a98 11 days ago 448MB
mysql latest 2fe463762680 11 days ago 514MB
hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
[root@localhost ~]# docker rmi 9f35042c6a98
Untagged: mysql:5.7
Untagged: mysql@sha256:360c7488c2b5d112804a74cd272d1070d264eef4812d9a9cc6b8ed68c3546189
Deleted: sha256:9f35042c6a98363147ae456147643a3d14c484640f13f4ab207cf2c296839baf
Deleted: sha256:69a5732b5b989ff688326db6354b0f50165a71cfe7579b285054b561fb3c5143
Deleted: sha256:448b1f9cb8f126363f0e809e0e450c493ca1e725715127a258c5346fcae7cd8a
Deleted: sha256:4064542818b4bf92f293da870d3ea1413a20d0c1a83f72917c50986880255338
Deleted: sha256:8ca7f5e08bac7aa39cf9b8b79bf40669373b9aed45ec76eb0fa55109350b6672
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 2fe463762680 11 days ago 514MB
hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
[root@localhost ~]#
(2)docker rmi -f 镜像id 根据镜像id强制删除镜像
一般常用加 -f 的方式删除
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 9f35042c6a98 11 days ago 448MB
mysql latest 2fe463762680 11 days ago 514MB
hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
[root@localhost ~]# docker rmi -f 2fe463762680
Untagged: mysql:latest
Untagged: mysql@sha256:4fcf5df6c46c80db19675a5c067e737c1bc8b0e78e94e816a778ae2c6577213d
Deleted: sha256:2fe4637626805dc6df98d3dc17fa9b5035802dcbd3832ead172e3145cd7c07c2
Deleted: sha256:e00bdaa10222919253848d65585d53278a2f494ce8c6a445e5af0ebfe239b3b5
Deleted: sha256:83411745a5928b2a3c2b6510363218fb390329f824e04bab13573e7a752afd50
Deleted: sha256:e8e521a71a92aad623b250b0a192a22d54ad8bbeb943f7111026041dce20d94f
Deleted: sha256:024ee0ef78b28663bc07df401ae3a258ae012bd5f37c2960cf638ab4bc04fafd
Deleted: sha256:597139ec344c8cb622127618ae21345b96dd23e36b5d04b071a3fd92d207a2c0
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 9f35042c6a98 11 days ago 448MB
hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
[root@localhost ~]#
(3)docker rmi -f $(docker images -aq) 删除所有镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 9f35042c6a98 11 days ago 448MB
mysql latest 2fe463762680 11 days ago 514MB
hello-world latest feb5d9fea6a5 2 weeks ago 13.3kB
[root@localhost ~]# docker rmi -f $(docker images -aq)
Untagged: mysql:5.7
Untagged: mysql@sha256:360c7488c2b5d112804a74cd272d1070d264eef4812d9a9cc6b8ed68c3546189
Deleted: sha256:9f35042c6a98363147ae456147643a3d14c484640f13f4ab207cf2c296839baf
Deleted: sha256:69a5732b5b989ff688326db6354b0f50165a71cfe7579b285054b561fb3c5143
Deleted: sha256:448b1f9cb8f126363f0e809e0e450c493ca1e725715127a258c5346fcae7cd8a
Deleted: sha256:4064542818b4bf92f293da870d3ea1413a20d0c1a83f72917c50986880255338
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@localhost ~]#