docker基础_镜像使用

一: 查看本地镜像

  • 命令: 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 ~]# 
相关推荐
啦啦啦啦啦zzzz2 小时前
moduo网络库 Acceptor TcpConnection
服务器·网络·c++·reactor·网络库
游戏开发爱好者82 小时前
App Store 上传 IPA 自动化,.p8 密钥认证与 CI/CD 接入实战
android·运维·ci/cd·小程序·uni-app·自动化·iphone
天疆说2 小时前
04 稳定性与性能调优实录:OOM 崩溃、并发槽位、前缀缓存与 DSpark 调参
linux·运维·缓存
微硬创新2 小时前
大点数模拟量采集落地:耐达讯自动化32路0-20mA适配PROFINET总线实践解析
运维·人工智能·网络协议·自动化·信息与通信
星卯教育tony2 小时前
NOI Linux 2.0 服务器多用户网页桌面部署方案(腾讯云轻量Ubuntu20.04专属版 CSP复赛比赛环境搭建免安装虚拟机 )
linux·服务器·腾讯云
7177772 小时前
如何搭建信创研发交付体系?Gitee DevOps 国产化适配、安全与流水线能力解析
安全·gitee·devops
猫吃了源码3 小时前
CentOS7使用Kubeadm安装部署K8s(Kubernetes)最新稳定版本1.26.x
云原生·容器·kubernetes
GIS数据转换器3 小时前
村镇无人机物流配送与跨域监测一体化平台
大数据·运维·人工智能·科技·无人机
Forever Nore3 小时前
LeetCode 14 最长公共前缀 - 纵向扫描
linux·服务器·leetcode
拂拉氏3 小时前
【知识讲解】 Linux权限相关知识讲解
linux·权限