Docker04-镜像

镜像介绍

镜像是Docker的三大核心概念之一。
Docker运行容器前需要本地存在对应的镜像,如果镜像不存在本地,Docker会尝试先从默认镜像仓库下载(默认使用Docker Hub公共注册服务器中仓库),用户也可以通过配置,使用自定义的镜像仓库。

获取镜像

命令:docker pull <registry>/<name>:<tag>

guanfuchang@ubuntu:~$ docker pull --help

Usage:  docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Pull an image or a repository from a registry

Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
      --platform string         Set platform if server is multi-platform capable

案例:获取 redis 5.0.0的镜像

  1. 先到远程仓库进行搜索 https://hub.docker.com/

获取最新的Redis,则只需要执行docker pull redis,这里我们指定版本号,则我们需要在Tag中找到是否存在对应的镜像。

2.下载镜像 执行命令 docker pull redis:5.0

root@ubuntu:/home/guanfuchang# docker pull redis:5.0
5.0: Pulling from library/redis
f17d81b4b692: Downloading [=======>                                           ]  3.226MB/22.49MB
b32474098757: Download complete 
8980cabe8bc2: Download complete 
e614c66c2b9c: Downloading [==========>                                        ]  2.485MB/11.76MB
6eb43ec9256b: Download complete 
394ecf5f46d4: Download complete 

查询本地镜像

查询本地镜像,命令docker images

root@ubuntu:/home/guanfuchang# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               5.0                 415381a6cb81        5 days ago          94.9MB

搜索镜像

搜索镜像,命令 docker search <镜像名>

root@ubuntu:/home/guanfuchang# docker search redis
NAME                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
redis                             Redis is an open source key-value store that…   6062                [OK]                
bitnami/redis                     Bitnami Redis Docker Image                      94                                      [OK]
google/guestbook-python-redis     A simple guestbook example written in Python…   1                                       
tiredofit/redis                   Redis Server w/ Zabbix monitoring and S6 Ove…   1                                       [OK]

删除镜像

删除镜像命令 docker rmi <镜像ID>

[warning]注意:删除镜像时,要先删除所有用到该镜像的容器。

root@ubuntu:/home/guanfuchang# docker rmi --help

Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]

Remove one or more images

Options:
  -f, --force      Force removal of the image
      --no-prune   Do not delete untagged parents

案例:删除redis:latest镜像

root@ubuntu:/home/guanfuchang# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               5.0                 415381a6cb81        5 days ago          94.9MB
redis               latest              415381a6cb81        5 days ago          94.9MB
root@ubuntu:/home/guanfuchang# 
root@ubuntu:/home/guanfuchang# docker rmi redis:latest
Untagged: redis:latest
root@ubuntu:/home/guanfuchang# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               5.0                 415381a6cb81        5 days ago          94.9MB

镜像加速

通过上面的实操例子,我们有可能会发现下载镜像的速度非常慢,那是因为Docker默认直接到Docker Hub中下载,Docker Hub是国外的网站,访问自然会慢一些,甚至会出现下载失败。在国内,阿里云,163都提供了docker仓库,并且阿里云还提供了加速功能,因此,我们可以通过设置使用阿里云仓库,便可以得到加速的效果。
配置阿里云镜像加速步骤:

  1. 注册阿里云,进入控制台 https://www.aliyun.com

  2. 在产品与服务菜单中,选择“容器镜像服务”,便可以找到菜单“镜像加速器”

  3. 根据文档说明,镜像加速器配置

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://6z3kxtoq.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

配置后镜像加速器后,不妨可以测试下载一个rabbitmq试一下,这个时候会发现下载速度会非常快。

root@ubuntu:/home/guanfuchang# docker search rabbitmq

:-:
***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值