Docker学习02:镜像管理

本文详细介绍了Docker镜像的基础知识,包括镜像的概念、主要分类、镜像加速器的配置方法,以及镜像的基本操作如搜索、拉取、查看、打标签、导出、删除和导入等。

一、什么是镜像

镜像就是打包好的环境与应用。

二、镜像的主要分类

  1. 操作系统类(如centos,ubuntu)
  2. 应用程序类(如web站点)

三、镜像加速器

国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。国内很多云服务商都提供了国内加速器服务。

添加国内镜像仓库

// 这里以网易的镜像仓库为例子
[root@docker ~]# vi /etc/docker/daemon.json
{
  "registry-mirrors": [
    "https://hub-mirror.c.163.com"
  ]
}

重新启动服务

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

检查加速器是否生效

执行$ docker info,如果从结果中看到了如下内容,说明配置成功.

Registry Mirrors:
 https://hub-mirror.c.163.com/

四、镜像基础操作

4.1 搜素镜像

docker search [关键字]

[root@docker ~]# docker search nginx
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                              Official build of Nginx.                        12908               [OK]                
jwilder/nginx-proxy                Automated Nginx reverse proxy for docker con…   1761                                    [OK]
richarvey/nginx-php-fpm            Container running Nginx + PHP-FPM capable of…   760                                     [OK]
linuxserver/nginx                  An Nginx container, brought to you by LinuxS…   102

4.2 拉取镜像

docker pull [image:tag]

不加tag,默认latest版本

[root@docker ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
c499e6d256d6: Pull complete 
74cda408e262: Pull complete 
ffadbd415ab7: Pull complete 
Digest: sha256:282530fcb7cd19f3848c7b611043f82ae4be3781cb00105a1d593d7e6286b596
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

4.3 查看镜像列表

docker imagesdocker image ls

[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              ed21b7a8aee9        34 hours ago        127MB

[root@docker ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              ed21b7a8aee9        34 hours ago        127MB

4.4 给镜像打标签

docker tag

[root@docker ~]# docker tag nginx:latest nginx:v1.1

[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              ed21b7a8aee9        34 hours ago        127MB
nginx               v1.1                ed21b7a8aee9        34 hours ago        127MB

4.5 导出镜像

docker save

// -o 指定导出路径
[root@docker ~]# docker save -o /data/nginx-v1.1.tar.gz nginx:v1.1
[root@docker ~]# ll /data/
total 127560
-rw------- 1 root root 130618880 Apr  1 20:58 nginx-v1.1.tar.gz

4.6 删除镜像

docker rmi 或者docker image rm

[root@docker ~]# docker rmi nginx:v1.1 
Untagged: nginx:v1.1

[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              ed21b7a8aee9        34 hours ago        127MB

4.7导入镜像

docker load

[root@docker ~]# docker load -i /data/nginx-v1.1.tar.gz 
Loaded image: nginx:v1.1
[root@docker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              ed21b7a8aee9        34 hours ago        127MB
nginx               v1.1                ed21b7a8aee9        34 hours ago        127MB
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值