赞
踩
声明:本文乃“运维家”原创,转载请注明出处,更多内容请关注公众号“运维家”。
主旨
本文主要介绍docker镜像的相关操作和简单命令。
环境
linux环境
docker环境
查看已有镜像
语法:docker images
实例:
[yunweijia@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
[yunweijia@localhost ~]$
搜索镜像
语法:docker search 镜像名
实例:
[yunweijia@localhost ~]$ sudo docker search centos
下载镜像
语法:docker pull 镜像名:版本号 (如果不指定版本号,默认下载最新的)
实例:
[yunweijia@localhost ~]$ sudo docker pull centos:7
7: Pulling from library/centos
2d473b07cdd5: Pull complete
Digest: sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
Status: Downloaded newer image for centos:7
docker.io/library/centos:7
[yunweijia@localhost ~]$
再次查看的时候,就会发现有这个镜像了
[yunweijia@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos 7 eeb6ee3f44bd 4 months ago 204MB
[yunweijia@localhost ~]$
重命名镜像
语法:docker tag 原镜像名:版本号 新名字:新版本号
实例:
[yunweijia@localhost ~]$ sudo docker tag centos:7 yunweijia_centos:10
[yunweijia@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
centos 7 eeb6ee3f44bd 4 months ago 204MB
yunweijia_centos 10 eeb6ee3f44bd 4 months ago 204MB
[yunweijia@localhost ~]$
删除镜像
语法:docker rmi 镜像名:版本号
实例:
[yunweijia@localhost ~]$ sudo docker rmi centos:7
Untagged: centos:7
Untagged: centos@sha256:9d4bcbbb213dfd745b58be38b13b996ebb5ac315fe75711bd618426a630e0987
再次查看的时候,发现对应镜像就消失了
[yunweijia@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
yunweijia_centos 10 eeb6ee3f44bd 4 months ago 204MB
[yunweijia@localhost ~]$
导出镜像
语法:docker save 镜像名:版本号 > 保存位置
实例:
[yunweijia@localhost ~]$ sudo docker save yunweijia_centos:10 > /home/yunweijia/centos_7.tar
删除镜像,以供下面我们做导入验证
[yunweijia@localhost ~]$ sudo docker rmi yunweijia_centos:10
Untagged: yunweijia_centos:10
Deleted: sha256:eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9
Deleted: sha256:174f5685490326fc0a1c0f5570b8663732189b327007e47ff13d2ca59673db02
[yunweijia@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
[yunweijia@localhost ~]$
导入镜像
语法:docker load < 保存位置
实例:
[yunweijia@localhost ~]$ sudo docker load < /home/yunweijia/centos_7.tar
174f56854903: Loading layer [==================================================>] 211.7MB/211.7MB
Loaded image: yunweijia_centos:10
[yunweijia@localhost ~]$
再次查看现有镜像
[yunweijia@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 4 months ago 13.3kB
yunweijia_centos 10 eeb6ee3f44bd 4 months ago 204MB
[yunweijia@localhost ~]$
至此,镜像的简单命令介绍完毕。
下一章:docker容器的基本操作
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。