一: 查看本地镜像
- 命令: docker image list
bash
[root@localhost ~]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
docker_image_commit 7 6f7eed944dac 5 weeks ago 161MB
192.168.255.157:5000/nginx latest 93165d051206 6 weeks ago 161MB
nginx latest 93165d051206 6 weeks ago 161MB
registry latest 53c26cd62311 2 months ago 62.4MB
mysql 5.7 5107333e08a8 2 years ago 501MB
uifd/ui-for-docker latest 965940f98fa5 9 years ago 8.1MB
centos 5 1ae98b2c895d 9 years ago 285MB
[root@localhost ~]#
二: 搜索官方镜像
由于国外网站访问不了,我们这里是在国内镜像站搜索镜像
- 命令:docker search 镜像站域名/镜像名
bash
[root@localhost ~]# docker search docker.1ms.run/centos7
NAME DESCRIPTION STARS OFFICIAL
paigeeworld/centos7 Centos7 with apache, iperf3, nmap, ssh 7
lamho/centos7 2
rpmbuild/centos7 CentOS 7 RPM package building environment 18
getgambacom/centos7 CentOS7 1
spack/centos7 CentOS 7 with Spack preinstalled 2
rmtm/centos7 CentOS7 Baseline for RMTM 0
henker/centos7 0
0702/centos7 A centos7 with usual utils 0
nodesource/centos7 The Official NodeSource Docker Images 2
jinwoo/centos7 centos7 0
caio2k/centos7 centos7 with supervisord and vagrant user 0
roboxes/centos7 A generic CentOS 7 base image. 4
vearsa/centos7 0
m411momo/centos7 ZSH Shell CentOS7 0
jeongho/centos7 Docker image for centos7 0
pantsbuild/centos7 0
lstrcm/centos7 0
level077/centos7 centos7 0
waffleimage/centos7 Centos:7 with systemd and ssh running 0
charlesjimi/centos7 my linux centos7 make docker img 0
blankhang/centos7 centos7 with chinese lanugage and openjdk8 1... 0
linfx0/centos7 CentOS7 Repository 0
kolab/centos7 Kolab 16 based on CentOS 7 5
nitra/centos7 Container CentOS7 with systemd 1
nclans/centos7 0
[root@localhost ~]#
三: 按星级搜索镜像
按星级搜索镜像,实际上就是在搜索镜像命令的基础上面加上 -f stars=数字 即可
bash
# 这里我们搜索stars大于10的镜像
[root@localhost ~]# docker search docker.1ms.run/centos7 -f stars=10
NAME DESCRIPTION STARS OFFICIAL
rpmbuild/centos7 CentOS 7 RPM package building environment 18
[root@localhost ~]#
四: 拉取镜像
- 命令:docker pull 镜像名
- 注意:如果镜像名后面不跟版本号,我们默认拉取的是最新的版本号
bash
[root@localhost ~]# docker pull centos:7
7: Pulling from library/centos
2d473b07cdd5: Already exists
Digest: sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4
Status: Downloaded newer image for centos:7
docker.io/library/centos:7
[root@localhost ~]#
五: 查看镜像详情
查看镜像详细信息,需要通过镜像ID,docker image list 可以看到已经下载的本地镜像ID
- 命令:docker image inspect 镜像ID
bash
[root@localhost ~]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
docker_image_commit 7 6f7eed944dac 5 weeks ago 161MB
192.168.255.157:5000/nginx latest 93165d051206 6 weeks ago 161MB
nginx latest 93165d051206 6 weeks ago 161MB
registry latest 53c26cd62311 2 months ago 62.4MB
mysql 5.7 5107333e08a8 2 years ago 501MB
centos 7 eeb6ee3f44bd 4 years ago 204MB
uifd/ui-for-docker latest 965940f98fa5 9 years ago 8.1MB
centos 5 1ae98b2c895d 9 years ago 285MB
[root@localhost ~]# docker inspect 93165d051206
[
{
"Id": "sha256:93165d051206cc2ee6804a233effad28ed3db70faba8f86ee5b4ea770e11d6ac",
"RepoTags": [
"192.168.255.157:5000/nginx:latest",
"nginx:latest"
],
"RepoDigests": [
"192.168.255.157:5000/nginx@sha256:dc0c700cbecf47f20bd5b5875c7dc878f6f5587dd7da251d369eafd3678004ff",
"nginx@sha256:800e7c98538c6bf725f5177e841aa720ae0ed1c378bbea368b6330bfe18a36b3"
],
六: 删除镜像
命令:
- 删除镜像:docker rmi 镜像id
- 强制删除:在最后加上 --force
- 删除所有镜像:docker rmi $(docker images -q)
- 查看镜像id: docker images -q
bash
# 删除单个镜像
[root@localhost ~]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
docker_image_commit 7 6f7eed944dac 5 weeks ago 161MB
192.168.255.157:5000/nginx latest 93165d051206 6 weeks ago 161MB
nginx latest 93165d051206 6 weeks ago 161MB
registry latest 53c26cd62311 2 months ago 62.4MB
mysql 5.7 5107333e08a8 2 years ago 501MB
centos 7 eeb6ee3f44bd 4 years ago 204MB
uifd/ui-for-docker latest 965940f98fa5 9 years ago 8.1MB
centos 5 1ae98b2c895d 9 years ago 285MB
[root@localhost ~]# docker rmi centos:7
Untagged: centos:7
Untagged: centos@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4
Deleted: sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9
[root@localhost ~]# docker rmi 6f7eed944dac
Untagged: docker_image_commit:7
Deleted: sha256:6f7eed944dac11d726165a6bd5f01aefccf546c035d8b8c56e6883ca4da16191
Deleted: sha256:24f3a40fd1def6ffb1f4b5445ed58689efe9109b01ab80495b57cf08bd20590f
[root@localhost ~]#
七: 给镜像打tag
给已有的镜像添加一个新的 "标签(tag)",相当于给镜像起一个 "别名"。
- 命令: docker tag 源镜像名 新起的镜像名
bash
[root@localhost ~]# docker tag centos:5 centos:5.1
[root@localhost ~]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.255.157:5000/nginx latest 93165d051206 6 weeks ago 161MB
nginx latest 93165d051206 6 weeks ago 161MB
registry latest 53c26cd62311 2 months ago 62.4MB
mysql 5.7 5107333e08a8 2 years ago 501MB
uifd/ui-for-docker latest 965940f98fa5 9 years ago 8.1MB
centos 5 1ae98b2c895d 9 years ago 285MB
centos 5.1 1ae98b2c895d 9 years ago 285MB
[root@localhost ~]#
八: 查看镜像制作过程
- 命令:docker history 镜像名
bash
[root@localhost ~]# docker history centos:5
IMAGE CREATED CREATED BY SIZE COMMENT
1ae98b2c895d 9 years ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 9 years ago /bin/sh -c #(nop) LABEL name=CentOS Base Im... 0B
<missing> 9 years ago /bin/sh -c #(nop) ADD file:811d2948907b0dbea... 285MB
<missing> 9 years ago /bin/sh -c #(nop) MAINTAINER The CentOS Pro... 0B
[root@localhost ~]#