Docker images导出和导入

镜像的导出

语法格式
docker save imageID > test.tar

举例:

[root@controller ~]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
goharbor/harbor-db        v2.1.1              1989b7290300        18 months ago       168MB
goharbor/prepare          v2.1.1              cbb89d3f1a58        18 months ago       160MB

[root@controller ~]# docker save goharbor/harbor-db:v2.1.1 > harbor-db.tar

镜像的导入

语法格式
docker load < test.tar

[root@controller ~]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
goharbor/harbor-db        v2.1.1              1989b7290300        18 months ago       168MB
goharbor/prepare          v2.1.1              cbb89d3f1a58        18 months ago       160MB
[root@controller ~]# docker rmi goharbor/harbor-db:v2.1.1
Untagged: harbor-db:v2.1.1
Deleted: sha256:456498165489156564616549816565a6e6bd89e1ce40096b89dd49d6e9d62bc8
Deleted: sha256:dsagfasdhgfdshfdsgreg541s4fdgfd4gdf3296f5775c53e3ee731972e253600
[root@controller ~]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
goharbor/prepare          v2.1.1              cbb89d3f1a58        18 months ago       160MB
[root@controller ~]# docker load < harbor-db.tar
60685807648a: Loading layer [==================================================>] 442.7 MB/442.7 MB
[root@controller ~]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
<none>                    <none>              90457edaf6ff        7 hours ago         168MB
goharbor/prepare          v2.1.1              cbb89d3f1a58        18 months ago       160MB
[root@controller ~]# docker tag 90457edaf6ff  harbor-db:v2.1.1
[root@controller ~]# 
[root@controller ~]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
goharbor/harbor-db        v2.1.1              1989b7290300        18 months ago       168MB
goharbor/prepare          v2.1.1              cbb89d3f1a58        18 months ago       160MB

docker保存多个镜像

docker images | grep -v REPOSITORY | awk 'BEGIN{OFS=":";ORS=" "}{print $1,$2}'

docker save -o 123.tar `docker images | grep -v REPOSITORY | awk 'BEGIN{OFS=":";ORS=" "}{print $1,$2}'`

¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥
有问题评论区回复,或者私信
¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥

你可能感兴趣的:(docker,运维,centos)