Docker镜像管理
1.1获取镜像
镜像拉取
docker search centos //搜索镜像
docker pull centos:6.9 //拉取centos6.9镜像
docker pull centos:7.5.1804 //拉取centos7.5.1804镜像
docker pull nginx //拉取nginx镜像
1.2 镜像查看
命令:docker image ls
例:
[root@localhost ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest daee903b4e43 7 days ago 133MB
centos 7.5.1804 cf49811e3cdb 20 months ago 200MB
注:
标识镜像唯一性的方法:
(1)REPOSITORY:TAG
例:centos:7.5.1804
(2)IMAGE ID (sha256:64位的号码,默认只截取12位)
例:82f3b5f3c58
1.3 镜像详细信息查看
命令:docker image inspect (REPOSITORY:TAG or IMAGE ID )
例:
[root@localhost ~]# docker image inspect nginx:latest
例:
[root@localhost ~]# docker image inspect daee903b4e43
1.4 只查看镜像ID
命令:docker image ls -q
例:
[root@localhost ~]# docker image ls -q
daee903b4e43
2199b8eb8390
cf49811e3cdb
1.5 镜像的导入和导出
导出
命令:docker image save IMAGE ID > 导出的文件
例:
将nginx镜像导出到 /tmp/nginx.tar.gz
[root@localhost ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest daee903b4e43 7 days ago 133MB
centos 6.9 2199b8eb8390 20 months ago 195MB
centos 7.5.1804 cf49811e3cdb 20 months ago 200MB
[root@localhost ~]# docker image save daee903b4e43 > /tmp/nginx.tar.gz
导入
命令:docker image load -i 导入的文件
例:将上面导出的镜像导入
[root@localhost ~]# docker image load -i /tmp/nginx.tar.gz
f5600c6330da: Loading layer [==================================================>] 72.52MB/72.52MB
32048dd980c7: Loading layer [==================================================>] 64.54MB/64.54MB
e3a971c30b12: Loading layer [==================================================>] 3.072kB/3.072kB
5887d03dfc3d: Loading layer [==================================================>] 4.096kB/4.096kB
b9e73ac5343e: Loading layer [==================================================>] 3.584kB/3.584kB
Loaded image ID: sha256:daee903b4e436178418e41d8dc223b73632144847e5fe81d061296e667f16ef2
导入之后查看无标签
[root@localhost ~]# docker image ls -a
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> daee903b4e43 7 days ago 133MB
centos 6.9 2199b8eb8390 20 months ago 195MB
centos 7.5.1804 cf49811e3cdb 20 months ago 200MB
手动打标签
[root@localhost ~]# docker image tag daee903b4e43 nginx:latest
再次查看
[root@localhost ~]# docker image ls -a
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest daee903b4e43 7 days ago 133MB
centos 6.9 2199b8eb8390 20 months ago 195MB
centos 7.5.1804 cf49811e3cdb 20 months ago 200MB
1.6 镜像的删除
删除单个镜像:
命令:docker image rm -f IMAGE ID
例:[root@localhost ~]# docker image rm -f daee903b4e43
删除全部镜像:
命令:docker image rm -f `docker image ls -q`
慎用!!!