Docker容器镜像及其打包

容器镜像分类
1. 系统类镜像
2. 应⽤镜像
搜索镜像
# 默认docker.hub
docker search centos

下载镜像
docker pull centos
默认下载最新版本
1. 打包
[root@docker001 ~]# systemctl start docker.service
[root@docker001 ~]# docker save -o centos.tar
centos:latest
[root@docker001 ~]# ls
anaconda-ks.cfg centos.tar frp initserver.sh
[root@docker001 ~]# ls -lh centos.tar
-rw------- 1 root root 228M 8⽉ 22 20:58
centos.tar
2. 传输
C:\Users\Administrator>d:
D:\>scp root@10.1.1.50:~/centos.tar ./
root@10.1.1.50's password:
centos.tar
3. 删除镜像
[root@docker001 ~]# docker rmi 5d0da3dc9764
Error response from daemon: conflict: unable to
delete 5d0da3dc9764 (must be forced) - image is
being used by stopped container ccfb70e36225
# 报错
# 因为有容器正在使⽤
[root@docker001 ~]# docker ps --all
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
ccfb70e36225 centos:latest "/bin/bash" 23
hours ago Exited (137) 22 hours ago
c2
62646dad9c60 centos:latest "/bin/bash" 23
hours ago Exited (1) 23 hours ago
c1
#需要删除容器
[root@docker001 ~]# docker rm c1
c1
[root@docker001 ~]# docker rm c2
c2
[root@docker001 ~]# docker ps -all
CONTAINER ID IMAGE COMMAND CREATED STATUS
 PORTS NAMES
[root@docker001 ~]# docker rmi 5d0da3dc9764
Untagged: centos:latest
Untagged:
centos@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d6
7d534bbdee55bd6c473f432b177
Deleted:
sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc1
6c52c45d4847e53fadb6
Deleted:
sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c
35051aff89f853606b59
[root@docker001 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
4.导⼊到本地⽬录
[root@docker001 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[root@docker001 ~]# docker load --help
Usage: docker load [OPTIONS]
Load an image from a tar archive or STDIN
Aliases:
 docker image load, docker load
Options:
-i, --input string Read from tar archive file,
instead of STDIN
-q, --quiet Suppress the load output
[root@docker001 ~]# docker load -i centos.tar
74ddd0ec08fa: Loading layer
[==================================================
>] 238.6MB/238.6MB
Loaded image: centos:latest
[root@docker001 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED 
SIZE
centos latest 5d0da3dc9764 2 years ago 
231MB
5. 系统容器运⾏
[root@docker001 ~]# docker run -it --name=c0
centos:latest /bin/bash
[root@9fb6f46b3809 /]# exit
exit
[root@docker001 ~]# docker container run -it --
name=c1 centos:latest /bin/bash
[root@0b24d60a94c5 /]# exit
exit
[root@docker001 ~]#

整理

1. 将镜像打包
# 查看帮助⽂件
docker --help
# 找到save,可以将镜像保存为⼀个tar包
docker save --help
#查看save使⽤⽅式
# 查看现有的镜像
docker images
# dock save --output centos.tar centos:latest
ls
#...centos.tar...
#可以将tar发送给其他⽤户,也可作为备份
删除镜像
[root@localhost ~]# docker rmi centos:latest
Error response from daemon: conflict: unable to
remove repository reference "centos:latest" (must
force) - container 169f06f08805 is using its
referenced image 5d0da3dc9764
# 如果有这个镜像⽣成的容器正在使⽤,那么就⽆法使⽤rmi移除镜
像
# 删除容器,退出容器up状态
docker rm c0
#使⽤docker ps --all确定没有镜像
docker rmi centos:latest
tar 中引⼊镜像
docker --help
docker laod --help
docker load -i centos.tar centos:latest

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值