深入了解 docker 镜像

2019-04-09  本文已影响0人  tafanfly

从仓库下载镜像

可以使用命令docker pull 去下载相应的镜像, 例如下载官方Centos7

# sudo docker pull centos:7
$ sudo docker pull centos
Using default tag: latest
latest: Pulling from library/centos
8ba884070f61: Pull complete
Digest: sha256:8d487d68857f5bc9595793279b33d082b03713341ddec91054382641d14db861
Status: Downloaded newer image for centos:latest

上述没有写明注册服务器,默认从Docker Hub 公共注册服务器中的仓库中下载, 完整的命令如下:

sudo docker pull registry.hub.docker.com/centos:7

查找下载镜像

可以使用命令docker images查看本地存在的images。

$ sudo docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
centos                        7                  9f38484d220f        3 weeks ago         202MB
centos                       latest              9f38484d220f        3 weeks ago         202MB
hello-world                  latest              fce289e99eb9        3 months ago        1.84kB

• REPOSITORY: 仓库名称,比如 centos
• TAG : 镜像的标记,比如 7
• IMAGE ID : ID 号(唯一),如果相同则指同一镜像
• CREATED : 创建时间
• SIZE: 镜像大小

创建镜像

  1. 依据本地镜像直接创建 - 不建议,不利于团队维护

sudo docker commit -m "added folder" -a "tafanfly" d8c8fa13c844 newcentos:7

  1. 利用dockerfile文件创建 - 建议使用
    Dockerfile 创建镜像

其他镜像相关操作

  1. 上传镜像, 可以使用docker push命令将创建的镜像上传到仓库中。
  1. 导出镜像, 可以使用docker save命令从本地镜像库中导出镜像到本地。
$ sudo docker save -o centos_7.tar centos
$ ls
centos_7.tar
  1. 导入镜像, 可以使用docker load命令将本地镜像文件导入到本地镜像库中。

sudo docker load --input centos_7.tar

  1. 删除镜像, 可以使用docker rmi命令移除本地镜像。
    Note : 删除镜像前,首先要关掉相应的container 并删除它

sudo docker rmi centos
sudo docker rmi 9f38484d220f

上一篇 下一篇

猜你喜欢

热点阅读