docker基础_镜像使用
一: 查看本地镜像
- 命令: docker image list
[root@localhost ~]# docker image listREPOSITORY TAG IMAGE ID CREATED SIZE docker_image_commit76f7eed944dac5weeks ago 161MB192.168.255.157:5000/nginx latest 93165d0512066weeks ago 161MB nginx latest 93165d0512066weeks ago 161MB registry latest 53c26cd623112months ago62.4MB mysql5.75107333e08a82years ago 501MB uifd/ui-for-docker latest 965940f98fa59years ago8.1MB centos51ae98b2c895d9years ago 285MB[root@localhost ~]#二: 搜索官方镜像
由于国外网站访问不了,我们这里是在国内镜像站搜索镜像
- 命令:docker search 镜像站域名/镜像名
[root@localhost ~]# docker search docker.1ms.run/centos7NAME DESCRIPTION STARS OFFICIAL paigeeworld/centos7 Centos7 with apache, iperf3, nmap,ssh7lamho/centos72rpmbuild/centos7 CentOS7RPM package building environment18getgambacom/centos7 CentOS71spack/centos7 CentOS7with Spack preinstalled2rmtm/centos7 CentOS7 BaselineforRMTM0henker/centos700702/centos7 A centos7 with usual utils0nodesource/centos7 The Official NodeSource Docker Images2jinwoo/centos7 centos70caio2k/centos7 centos7 with supervisord and vagrant user0roboxes/centos7 A generic CentOS7base image.4vearsa/centos70m411momo/centos7 ZSH Shell CentOS70jeongho/centos7 Docker imageforcentos70pantsbuild/centos70lstrcm/centos70level077/centos7 centos70waffleimage/centos7 Centos:7 with systemd andsshrunning0charlesjimi/centos7 my linux centos7makedockerimg0blankhang/centos7 centos7 with chinese lanugage and openjdk81…0linfx0/centos7 CentOS7 Repository0kolab/centos7 Kolab16based on CentOS75nitra/centos7 Container CentOS7 with systemd1nclans/centos70[root@localhost ~]#三: 按星级搜索镜像
按星级搜索镜像,实际上就是在搜索镜像命令的基础上面加上-f stars=数字即可
# 这里我们搜索stars大于10的镜像[root@localhost ~]# docker search docker.1ms.run/centos7 -f stars=10NAME DESCRIPTION STARS OFFICIAL rpmbuild/centos7 CentOS7RPM package building environment18[root@localhost ~]#四: 拉取镜像
- 命令:docker pull 镜像名
- 注意:如果镜像名后面不跟版本号,我们默认拉取的是最新的版本号
[root@localhost ~]# docker pull centos:77: Pulling from library/centos 2d473b07cdd5: Already exists Digest: sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4 Status: Downloaded newer imageforcentos:7 docker.io/library/centos:7[root@localhost ~]#五: 查看镜像详情
查看镜像详细信息,需要通过镜像ID,docker image list 可以看到已经下载的本地镜像ID
- 命令:docker image inspect 镜像ID
[root@localhost ~]# docker image listREPOSITORY TAG IMAGE ID CREATED SIZE docker_image_commit76f7eed944dac5weeks ago 161MB192.168.255.157:5000/nginx latest 93165d0512066weeks ago 161MB nginx latest 93165d0512066weeks ago 161MB registry latest 53c26cd623112months ago62.4MB mysql5.75107333e08a82years ago 501MB centos7eeb6ee3f44bd4years ago 204MB uifd/ui-for-docker latest 965940f98fa59years ago8.1MB centos51ae98b2c895d9years 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
# 删除单个镜像[root@localhost ~]# docker image listREPOSITORY TAG IMAGE ID CREATED SIZE docker_image_commit76f7eed944dac5weeks ago 161MB192.168.255.157:5000/nginx latest 93165d0512066weeks ago 161MB nginx latest 93165d0512066weeks ago 161MB registry latest 53c26cd623112months ago62.4MB mysql5.75107333e08a82years ago 501MB centos7eeb6ee3f44bd4years ago 204MB uifd/ui-for-docker latest 965940f98fa59years ago8.1MB centos51ae98b2c895d9years ago 285MB[root@localhost ~]# docker rmi centos:7Untagged: centos:7 Untagged: centos@sha256:be65f488b7764ad3638f236b7b515b3678369a5124c47b8d32916d6487418ea4 Deleted: sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9[root@localhost ~]# docker rmi 6f7eed944dacUntagged: docker_image_commit:7 Deleted: sha256:6f7eed944dac11d726165a6bd5f01aefccf546c035d8b8c56e6883ca4da16191 Deleted: sha256:24f3a40fd1def6ffb1f4b5445ed58689efe9109b01ab80495b57cf08bd20590f[root@localhost ~]#七: 给镜像打tag
给已有的镜像添加一个新的 “标签(tag)”,相当于给镜像起一个 “别名”。
- 命令: docker tag 源镜像名 新起的镜像名
[root@localhost ~]# docker tag centos:5 centos:5.1[root@localhost ~]# docker image listREPOSITORY TAG IMAGE ID CREATED SIZE192.168.255.157:5000/nginx latest 93165d0512066weeks ago 161MB nginx latest 93165d0512066weeks ago 161MB registry latest 53c26cd623112months ago62.4MB mysql5.75107333e08a82years ago 501MB uifd/ui-for-docker latest 965940f98fa59years ago8.1MB centos51ae98b2c895d9years ago 285MB centos5.11ae98b2c895d9years ago 285MB[root@localhost ~]#八: 查看镜像制作过程
- 命令:docker history 镜像名
[root@localhost ~]# docker history centos:5IMAGE CREATED CREATED BY SIZE COMMENT 1ae98b2c895d9years ago /bin/sh-c#(nop) CMD ["/bin/bash"] 0B<missing>9years ago /bin/sh-c#(nop) LABEL name=CentOS Base Im… 0B<missing>9years ago /bin/sh-c#(nop) ADD file:811d2948907b0dbea… 285MB<missing>9years ago /bin/sh-c#(nop) MAINTAINER The CentOS Pro… 0B[root@localhost ~]#