docker镜像管理

1.查看镜像

[root@centos201 ~]# docker image ls  #  查看现有的镜像列表。
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   20 months ago   13.3kB
[root@centos201 ~]# 
[root@centos201 ~]# 
[root@centos201 ~]# docker image ls -q  # 只查看镜像的id
feb5d9fea6a5
[root@centos201 ~]# 
[root@centos201 ~]# docker images  # 等效于"docker image ls"
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   20 months ago   13.3kB
[root@centos201 ~]#

2.给镜像打标签

[root@centos201 ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   20 months ago   13.3kB
[root@centos201 ~]# 
[root@centos201 ~]# docker image tag hello-world centos-hello-world:v0.1
[root@centos201 ~]# 
[root@centos201 ~]# docker image ls 
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
hello-world             latest    feb5d9fea6a5   20 months ago   13.3kB
centos-hello-world   v0.1      feb5d9fea6a5   20 months ago   13.3kB
[root@centos201 ~]# 

3.本地镜像迁移

3.1.导出镜像到一个tar包的2种方式

导出镜像到一个tar包的2种方式:
[root@centos201 ~]# docker image ls 
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
hello-world             latest    feb5d9fea6a5   20 months ago   13.3kB
test-hello-world   v0.1      feb5d9fea6a5   20 months ago   13.3kB
[root@centos201 ~]# 
[root@centos201 ~]# docker image save test-hello-world:v0.1 > test-docker-hello-world.tar.gz
[root@centos201 ~]#
[root@centos201 ~]# docker image save --output test-docker-hello-world-v2.tar.gz test-hello-world:v0.1 

3.2.从一个tar包导入镜像的两种方式

[21:24:47 root@centos202 ~]#scp * 10.0.0.211:~


root@ubuntu211:~# docker image load < oldboyedu-docker-hello-world-v2.tar.gz
root@ubuntu211:~# 
root@ubuntu211:~# docker image load -i oldboyedu-docker-hello-world-v2.tar.gz

4.下载镜像

[root@centos201 ~]# docker pull nginx:1.14.2  # 下载一个nginx版本号为1.14.2的镜像。

[root@centos201 ~]# docker pull mysql:8.0  # 下载一个mysql版本号为8.0的镜像。

[root@centos201 ~]# docker pull docker.elastic.co/elasticsearch/elasticsearch:7.17.5  #  去第三方镜像仓库下载镜像
	
[root@centos201 ~]# docker pull tomcat:9   # 下载一个tomcat9的镜像

5.删除镜像

[root@centos201 ~]# docker image rm hello-world  # 删除指定的镜像的名称。


root@ubuntu211:~# docker image rm -f feb5d9fea6a5  # 基于镜像ID强制删除镜像,尽管该镜像被其他镜像或容器引用。


[root@centos202 ~]# docker image rm -f `docker image ls -q`   # 删除本地的所有镜像。
posted @ 2024-01-21 18:49  只为心情愉悦  阅读(11)  评论(0编辑  收藏  举报