2、docker镜像管理

docker镜像管理

镜像搜索:

docker search alpine

镜像拉取:

docker pull 仓库服务器:端口/项目名称/镜像名称:tag(版本)号

# docker pull httpd

# docker pull centos

# docker pull alpine

本地镜像查看:

docker images

# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
httpd        latest    dabbfbe0c57b   19 months ago   144MB
alpine       latest    c059bfaa849c   20 months ago   5.59MB
centos       latest    5d0da3dc9764   23 months ago   231MB

REPOSITORY :镜像所属的仓库名称

TRG:镜像版本号(标识符),默认为 latest

IMAGE ID:镜像唯一 ID 标示

CREATED :镜像创建时间

SIZE:镜像的大小

镜像导出:

docker save 镜像名称:tag号 -o 路径名称.tar.gz

docker save 镜像名称:tag号 > 路径名称.tar.gz

# docker save http >/opt/httpd.tar.gz
# cd /opt
# tar xvf httpd.tar.gz -C /opt/httpd
# cd /opt/httpd
# ll
总用量 48
drwxr-xr-x 7 root root 4096 87 16:51 ./
drwxr-xr-x 5 root root 4096 87 16:51 ../
drwxr-xr-x 2 root root 4096 1221  2021 3e2c53861194222a8310998455af993e2b4260a4339d82f8aa16fb4a2c11f4dd/
drwxr-xr-x 2 root root 4096 1221  2021 5df3f744c961b85bb93947d6a4288543c06e64b3130562ae7be85fdc9f7a5691/
drwxr-xr-x 2 root root 4096 1221  2021 65fb84ffd54eb66acfe56108378bbdbc3faa6ba7874754f6124daf1ec08d8ce1/
drwxr-xr-x 2 root root 4096 1221  2021 d81667c6306409721397d538191336304934d54ba16e9ffba41832e4ff68ff04/
-rw-r--r-- 1 root root 9040 1221  2021 dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34.json
drwxr-xr-x 2 root root 4096 1221  2021 ea9618b889961942d4bd9eaa21f82882e1207e335eecb38da4728129ff6d6ccd/
-rw-r--r-- 1 root root  509 11  1970 manifest.json
-rw-r--r-- 1 root root   88 11  1970 repositories
root@ubuntu-n1:/opt/httpd# cat manifest.json 
[{"Config":"dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34.json","RepoTags":["httpd:latest"],"Layers":["5df3f744c961b85bb93947d6a4288543c06e64b3130562ae7be85fdc9f7a5691/layer.tar","ea9618b889961942d4bd9eaa21f82882e1207e335eecb38da4728129ff6d6ccd/layer.tar","d81667c6306409721397d538191336304934d54ba16e9ffba41832e4ff68ff04/layer.tar","3e2c53861194222a8310998455af993e2b4260a4339d82f8aa16fb4a2c11f4dd/layer.tar","65fb84ffd54eb66acfe56108378bbdbc3faa6ba7874754f6124daf1ec08d8ce1/layer.tar"]}]    #

#分层为了方便文件的共用,即相同的文件可以共用

[{"Config":" 配 置 文 件 .json","RepoTags":["docker.io/nginx:latest"],"Layers":[" 分 层1/layer.tar","分层 2 /layer.tar","分层 3 /layer.tar"]}]

镜像导入:

docker image load -i 路径名.tar.gz

docker image load < 路径名.tar.gz

#拷贝到需要镜像的主机
# scp httpd.tar.gz 192.168.75.79:/opt/

#进行导入操作

# docker image load -i /opt/httpd.tar.gz 
1da636a1aa95: Loading layer [==================================================>]  3.072kB/3.072kB
15e4bf5d0804: Loading layer [==================================================>]   2.72MB/2.72MB
9cff3206f9a6: Loading layer [==================================================>]  61.08MB/61.08MB
deefaa620a71: Loading layer [==================================================>]  3.584kB/3.584kB
Loaded image: httpd:latest
# docker images
REPOSITORY      TAG        IMAGE ID       CREATED         SIZE
testa           v1         4f2addfc8a63   13 days ago     5.59MB
swthink/nginx   test1      0020ab081f59   2 weeks ago     9.32MB
nginx           latest     605c77e624dd   19 months ago   141MB
httpd           latest     dabbfbe0c57b   19 months ago   144MB  ##导入的镜像
debian          11.2       6f4986d78878   19 months ago   124MB
alpine          latest     c059bfaa849c   20 months ago   5.59MB
ubuntu          18.04      5a214d77f5d7   22 months ago   63.1MB
centos          7.9.2009   eeb6ee3f44bd   23 months ago   204MB
[root@swthink opt]# 

删除容器:

如果要删除一个容器,必须先停止容器的运行后删除,除非加-f选项,强制删除

docker rm 容器ID/容器名称

docker rm -f 容器ID/容器名称 强制删除容器

# docker ps -aq  #
1826820d0999
4d0bc20857f6
7959712ec28c

# docker stop `docker ps -aq` #批量停止容器

# docker rm `docker ps -aq`   #批量删除容器

删除镜像:

docker rmi ID/镜像名称

完全无关联才能删除镜像

# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
httpd        latest    dabbfbe0c57b   19 months ago   144MB
alpine       latest    c059bfaa849c   20 months ago   5.59MB
centos       latest    5d0da3dc9764   23 months ago   231MB

# docker rmi httpd
Untagged: httpd:latest
Untagged: httpd@sha256:0954cc1af252d824860b2c5dc0a10720af2b7a3d3435581ca788dff8480c7b32
Deleted: sha256:dabbfbe0c57b6e5cd4bc089818d3f664acfad496dc741c9a501e72d15e803b34
Deleted: sha256:0e16a5a61bcb4e6b2bb2d746c2d6789d6c0b66198208b831f74b52198d744189
Deleted: sha256:f79670638074ff7fd293e753c11ea2ca0a2d92ab516d2f6b0bac3f4c6fed5d86
Deleted: sha256:189d55cdd18e4501032bb700a511c2d69c82fd75f1b619b5218ea6870e71e4aa
Deleted: sha256:cb038ed3e490a8c0f195cf135ac0d27dd8d3872598b1cb858c2666f2dae95a61
Deleted: sha256:2edcec3590a4ec7f40cf0743c15d78fb39d8326bc029073b41ef9727da6c851f

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值