• 2.docker镜像的导入导出


    概述

    docker 常用命令

    本章节使用到的命令,总结在此,后面有使用案例。

    命令作用
    docker images显示镜像
    docker rmi $(docker images -q)删除系统上所有的镜像
    docker rmi -f强制删除多个镜像 :docker rmi -f nginx mysql
    docker save -o <导出路径/文件名.tar> <镜像名称>
    docker load -i <导出路径/文件名.tar>导入镜像

    下载

    生产的机器一般是 无外网环境 ,所以 docker 要离线安装,镜像也需要离线安装。
    所以需要一台连网的机器,先将镜像下载,再导出

    appledeMacBook-Pro:~ hyl$ docker images
    REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
    pangliang/rocketmq-console-ng   latest              ce1afb55c045        4 years ago         118MB
    rocketmqinc/rocketmq            latest              09bbc30a03b6        4 years ago         380MB
    appledeMacBook-Pro:~ hyl$ 
    appledeMacBook-Pro:~ hyl$ docker rmi $(docker images -q)
    Untagged: pangliang/rocketmq-console-ng:latest
    Untagged: pangliang/rocketmq-console-ng@sha256:630eb2fb9f144637bb6f77af37e23426e0c0596b0d46873f1c921f8f6c4aa17a
    Deleted: sha256:ce1afb55c04576af89153d98789d55d8bca0ed5c30a456bc9c9161859a9e6f9f
    Deleted: sha256:fdde7851a1539da25abd154a97e6f47a5166256e1ff37768d8e92016b37f54ae
    Deleted: sha256:aba8cd4318a8a15f59f305368e49cc3bbd0d6d72171a0b24d08cc00513b14ef4
    Deleted: sha256:c318fbba92645a83843c387bd78497e7b143ecc7f5ed99dcb7d38fc62442c02a
    Deleted: sha256:f1b5933fe4b5f49bbe8258745cf396afe07e625bdab3168e364daf7c956b6b81
    Untagged: rocketmqinc/rocketmq:latest
    Untagged: rocketmqinc/rocketmq@sha256:b08556227ad8d169b7927f4c48335877cb10060e6781374ce5a644ea29f6fbe1
    Deleted: sha256:09bbc30a03b682786ad205beb772a382d4cecc8a521206d7b3c50e95fb725530
    Deleted: sha256:9b56b922584897d7008163dc149c70a987fac1ae6b1929f4412efe9f8c2ede78
    Deleted: sha256:33183233106a7e3aa85b0d2bc1d65260f9c4d78040c78370940ecc2331ea313d
    Deleted: sha256:2f228f2a23dfa6754aede6994c84fb52386e0bb5a02226f0070f0eb0f44fd85e
    Deleted: sha256:8f9cb5d760f829ad52a340f773ff645db0138d0583b8ccf2b62554480707554c
    Deleted: sha256:7fa827024c4d1c03f341b9f5a28bc3cf37264c431ec4a3f7abdafeaf990f45d8
    Deleted: sha256:5cc9537c34c58cda2cf83d0d4fa991a508f89b1a86eada4d190878785b6f9172
    Deleted: sha256:ef8da6bbb9df05a886aae9a4175664802cef24582203f10dfe1d84ce00f8db1d
    Deleted: sha256:071d8bd765171080d01682844524be57ac9883e53079b6ac66707e192ea25956
    appledeMacBook-Pro:~ hyl$ docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    下载镜像

    appledeMacBook-Pro:~ hyl$ docker pull influxdb:1.8
    1.8: Pulling from library/influxdb
    2f088d622efd: Pull complete 
    de448b80f064: Pull complete 
    469105de3319: Pull complete 
    cdad387b3290: Pull complete 
    b9b6af5df828: Pull complete 
    20272ddaf2bf: Pull complete 
    708944893048: Pull complete 
    Digest: sha256:f02e9d97bd1edf36f343d0478b9e4d3bf0f4a7c30d59c4edca6acf2b6065f2a9
    Status: Downloaded newer image for influxdb:1.8
    docker.io/library/influxdb:1.8
    appledeMacBook-Pro:~ hyl$ docker pull grafana/grafana
    Using default tag: latest
    Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: TLS handshake timeout
    appledeMacBook-Pro:~ hyl$ docker pull grafana/grafana
    Using default tag: latest
    latest: Pulling from grafana/grafana
    7264a8db6415: Pull complete 
    3cf7ed17dad5: Pull complete 
    00fbaa4ff278: Pull complete 
    1712a81b1c5b: Pull complete 
    b82f661477d7: Pull complete 
    85d88afc7ec6: Pull complete 
    5aeff27f6208: Pull complete 
    2309246adff5: Pull complete 
    4a6fe4caa3c7: Pull complete 
    6309adfe5521: Pull complete 
    Digest: sha256:1ee0c54286b8ca09a3dd1419ff8653e7780a148a006ac088544203bb0affe550
    Status: Downloaded newer image for grafana/grafana:latest
    docker.io/grafana/grafana:latest
    appledeMacBook-Pro:~ hyl$ 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    导出

    将下载下来的 镜像 导出并且打包,上传至离线的服务器上,进行导入工作。

    docker save -o /Users/hyl/Desktop/jk/influxdb.tar influxdb:1.8
    docker save -o /Users/hyl/Desktop/jk/grafana.tar grafana/grafana:latest 
    
    • 1
    • 2

    操作如下图:
    在这里插入图片描述
    导出过程可能需要一些时间,取决于镜像的大小,所以需要耐心等待。

    导入镜像

    导出完成后,可以使用 docker load 命令验证导出的镜像。以下是载入镜像的示例命令:
    在这里插入图片描述

    [root@hadoop01 ~]# docker load -i ./influxdb.tar
    53ae7e5bcde8: Loading layer [==================================================>]  129.4MB/129.4MB
    47a0492361a1: Loading layer [==================================================>]  29.53MB/29.53MB
    ea498917da7b: Loading layer [==================================================>]  10.75kB/10.75kB
    18ae329703f8: Loading layer [==================================================>]    154MB/154MB
    63f6173a2112: Loading layer [==================================================>]  3.072kB/3.072kB
    99108cfee517: Loading layer [==================================================>]  2.048kB/2.048kB
    3ab566fe20ca: Loading layer [==================================================>]  5.632kB/5.632kB
    Loaded image: influxdb:1.8
    [root@hadoop01 ~]# docker load -i ./grafana.tar
    4693057ce236: Loading layer [==================================================>]  7.626MB/7.626MB
    bdf330023361: Loading layer [==================================================>]   2.56kB/2.56kB
    018ee2d8caca: Loading layer [==================================================>]  8.495MB/8.495MB
    7ccfea30313d: Loading layer [==================================================>]  10.19MB/10.19MB
    fb7a544ac307: Loading layer [==================================================>]  162.3kB/162.3kB
    4ee20b1f5366: Loading layer [==================================================>]   89.6kB/89.6kB
    5892380a6ea3: Loading layer [==================================================>]  189.1MB/189.1MB
    3c537f66dd33: Loading layer [==================================================>]  191.2MB/191.2MB
    bf5a90fccd9f: Loading layer [==================================================>]  37.89kB/37.89kB
    e14e42fdf9d7: Loading layer [==================================================>]   5.12kB/5.12kB
    Loaded image: grafana/grafana:latest
    [root@hadoop01 ~]# 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    如下图导入成功了
    在这里插入图片描述

    结束

    至此,docker 镜像的导入导出就结束了,如有问题,欢迎评论区留言。

  • 相关阅读:
    Spark(3):Spark运行环境
    Dynamics 365应用程序开发- 8.利用Dynamics 365中的Azure扩展
    挖矿宝藏之TCP/IP
    线性表的应用【线性表的合并】和【顺序有序表的合并】
    C语言从入门到精通第20天(结构体的使用)
    【JAVA后端开发】Part1--瑞吉外卖项目
    Fabric.js 复制粘贴元素
    Flutter 在 windows 上的开发环境设置
    linux安装rabbitmq(正式环境)
    Power BI 傻瓜入门 9. 设计和部署数据模型
  • 原文地址:https://blog.csdn.net/2301_79691134/article/details/134289054