实验环境

CentOS 7.5

安装并启动docker

yum install -y docker
systemctl start docker

镜像

安装镜像

docker pull [OPTIONS] NAME[:TAG|@DIGEST]

注:对于Docker镜像来说,如果不显式地指定TAG,则默认会选择 latest标签,即下载仓库中最新版本的镜像。

  • 从Docker Hub的CentOS仓库下载一个最新的CentOS操作系统的镜像。
[root@kvm ~]# docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
a02a4930cb5d: Pull complete
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for docker.io/centos:latest docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
a02a4930cb5d: Pull complete
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for docker.io/centos:latest docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
a02a4930cb5d: Pull complete
Digest: sha256:184e5f35598e333bfa7de10d8fb1cebb5ee4df5bc0f970bf2b1e7c7345136426
Status: Downloaded newer image for docker.io/centos:latest

注:该命令实际上下载的就是centos:latest镜像,目前最新的7.6.1810版本的镜像。

  • 从Docker Hub的CentOS仓库下载一个指定版本的CentOS操作系统的镜像。
[root@kvm ~]# docker pull centos:7.3.1611
Trying to pull repository docker.io/library/centos ...
7.3.1611: Pulling from docker.io/library/centos
b8e0383d5f94: Pull complete
Digest: sha256:6fe8d484f2897e2ea75f496bfb6792b539baf3e56880fce3b9b6505d76e266dd
Status: Downloaded newer image for docker.io/centos:7.3.1611

查看镜像信息

列出本地主机上已有的镜像

[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB
docker.io/centos 7.3.1611 1e20acd39495 3 months ago 192 MB
  • 各字段释义

    • REPOSITORY:来自于哪个仓库,比如centos仓库;
    • TAG:镜像的标签信息,比如7.3.1611;
    • IMAGE ID:镜像的ID号(唯一);
    • CREATED:创建时间;
    • SIZE:镜像大小。

创建镜像

创建镜像的方法主要有三种:基于已有镜像的容器创建、基于本地模板导入、基于Dockerfile创建;这里着重介绍前两种。

基于已有镜像的容器创建

  • 该方法实现创建的命令行格式
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

[root@kvm ~]# docker commit --help
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Create a new image from a container's changes
Options:
-a, --author string 作者信息
-c, --change list 提交的时候执行Dockerfile指令 (default [])
--help 帮助信息
-m, --message string 提交信息
-p, --pause 提交期间暂停容器运行
  • 实际操作创建一个新镜像

    • 启动一个镜像,然后做修改后退出
[root@kvm ~]# docker run -t -i docker.io/centos:7.3.1611 /bin/bash
[root@90d3b762f848 /]# touch test.txt
[root@90d3b762f848 /]# exit

注:记住容器 ID为90d3b762f848。

* 此时的该容器与原centos:7.3.1611镜像相比,已经发生改变,可执行docker commit命令来提交一个新的镜像;提交时可以使用ID或名称来指定容器。

[root@kvm ~]# docker commit -m "add a file named test.txt" -a "docker new" 90d3b762f848 www.wholj.com:7.3
sha256:3a51b6661c9f9c31ec8239405535cc57f782972f6eedf8452e2d8f4bce0bc2d6
[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
www.wholj.com 7.3 3a51b6661c9f 7 seconds ago 192 MB
docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB
docker.io/centos 7.3.1611 1e20acd39495 3 months ago 192 MB

镜像ID为3a51b6661c9f的镜像即为刚新增的。

基于本地模板导入

  • 该方法实现创建的命令行格式
[root@kvm /home/tools/ISO]# docker import --help
Usage: docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Import the contents from a tarball to create a filesystem image
Options:
-c, --change list Apply Dockerfile instruction to the created image (default [])
--help 帮助信息
-m, --message string 为此导入镜像设置提交信息
  • 实际操作创建一个新镜像
[root@kvm /home/tools/ISO]# cat centos-7-x86_64-minimal.tar.gz | docker import - www.wholj.com:7.5
sha256:4950a54ede5a5c0da704c6f74e6bcc43d440e83260b0752a926325035435a7dc
[root@kvm /home/tools/ISO]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
www.wholj.com 7.5 4950a54ede5a 10 seconds ago 435 MB
www.wholj.com 7.3 3a51b6661c9f 2 days ago 192 MB
docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB
docker.io/centos 7.3.1611 1e20acd39495 3 months ago 192 MB

镜像ID为4950a54ede5a的镜像即为刚新增的。

导出(save)和载入(load)镜像

导出镜像

将本地已有的镜像文件导出后可分享给其他人使用。

  • 导出镜像的命令行格式用法
docker save [OPTIONS] IMAGE [IMAGE...]

[root@kvm ~]# docker save --help
Usage: docker save [OPTIONS] IMAGE [IMAGE...]
Save one or more images to a tar archive (streamed to STDOUT by default)
Options:
--help 帮助信息
-o, --output string 从标准输出导出镜像到指定的文件中
  • 导出本地的docker.io/centos:latest镜像为文件centos_7.6.tar
[root@kvm ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
www.wholj.com 7.3 3a51b6661c9f About an hour ago 192 MB
docker.io/centos latest 1e1148e4cc2c 7 weeks ago 202 MB
docker.io/centos 7.3.1611 1e20acd39495 3 months ago 192 MB
[root@kvm ~]# ll
total 8
-rw-------. 1 root root 2090 Nov 30 11:33 anaconda-ks.cfg
-rw-------. 1 root root 1955 Nov 30 11:33 original-ks.cfg
[root@kvm ~]# docker save -o centos_7.6.tar docker.io/centos:latest
[root@kvm ~]# ll
total 205272
-rw-------. 1 root root 2090 Nov 30 11:33 anaconda-ks.cfg
-rw------- 1 root root 210186752 Jan 25 17:17 centos_7.6.tar
-rw-------. 1 root root 1955 Nov 30 11:33 original-ks.cfg
[root@kvm ~]#

载入镜像

将别人分享给自己的镜像导入到本地镜像库。

  • 载入镜像的命令行格式用法
docker load [OPTIONS]

[root@kvm ~]# docker load --help
Usage: docker load [OPTIONS]
Load an image from a tar archive or STDIN
Options:
--help 帮助信息
-i, --input string 从指定tar文件读入镜像内容
-q, --quiet Suppress the load output
  • 从指定文件导入镜像文件到本地镜像库
[root@kvm ~]# docker load -i ./centos_7.6.tar
Loaded image: docker.io/centos:latest

或者:

[root@kvm ~]# docker load < ./centos_7.6.tar
Loaded image: docker.io/centos:latest

注:上述命令将导入镜像及其相关的元数据信息(包括标签等)。导入成功后,可以使用docker images命令进行查看,与原镜像一致。

docker镜像 - 下载、创建镜像和导入导出镜像的更多相关文章

  1. docker 保存 加载(导入 导出镜像

    tensorflow 的docker镜像很大,pull一次由于墙经常失败.其实docker 可以将镜像导出再导入. 保存加载(tensorflow)镜像 1) 查看镜像 docker images 如 ...

  2. docker 导入导出镜像

    docker容器导入导出有两种方法: 一种是使用save和load命令 使用例子如下: docker save ubuntu:load>/root/ubuntu.tar docker load& ...

  3. docker导入导出镜像

    docker容器导入导出有两种方法: 一种是使用save和load命令 使用例子如下: docker save ubuntu:load>/root/ubuntu.tar docker load& ...

  4. docker离线导入导出镜像

    docker save -o mysqlies.tar 5ada6380f248(镜像id)    # 镜像id是要导出的 有镜像的机器  在有镜像的机器上执行docker load --input ...

  5. Oracle数据库的创建、数据导入导出

    如何结合Sql脚本和PL/SQL Developer工具来实现创建表空间.创建数据库.备份数据库.还原数据库等操作,然后实现Oracle对象创建.导入数据等操作,方便我们快速了解.创建所需要的部署Sq ...

  6. postgresql绿色版安装及Navicat创建数据库,导入导出sql

    转载:https://www.cnblogs.com/winkey4986/p/5360551.html 1.设置安装路径为:D:\soft\pgsql,数据存储路径为:D:\soft\pgsql\d ...

  7. docker进入mysql数据库并进行导入 导出

    一:导入 1.首先查看docker运行的容器: docker ps 2.将宿主机文件拷贝到docker容器中: docker cp 2020415.sql af491d5466ea:/opt/2020 ...

  8. phpMyAdmin教程 之 创建新用户/导入/导出数据库

    盗用了被人的教程. 需要看就点击进去吧.复制过来实在是过意不去 http://www.wpdaxue.com/phpmyadmin-import-export-database.html

  9. Docker的数据管理(下)——docke镜像的创建

    Docker的数据管理(下)--docke镜像的创建 1.基于现有镜像创建 2.基于本地模板创建 3.基于 dockerfile 创建 4.Dockerfile 镜像操作常用命令 5.dockerfi ...

随机推荐

  1. 题解 AT3717 【[ABC081A] Placing Marbles】

    题目传送门. 分析 我们可以把字符串中所有数加起来输出,那么到底怎么把一个字符变成一个数字呢.我们只需要减去字符\(0\)就可以了. 详细步骤 定义字符串\(s\)并将其输入. string s; c ...

  2. 事件分析法学习笔记(ESM)

    事件分析法基础学习笔记 1.定义   事件分析法是研究某事件的发生对组织价值的影响以及影响程度. 或者说研究特定事件对组织行为的影响. notes:事件分析法的关键点在于探讨所关注事件在某个时段产生的 ...

  3. C++-蓝桥杯-入门训练

    Fibonacci数列,快速幂 #include <cstdio> ][];}; ,MOD=; Matrix A,B,O,I; Matrix Mul(Matrix A,Matrix B){ ...

  4. Subway POJ - 2502 spfa

    #include<cstdio> #include<cmath> #include<cstring> #include<cstring> #includ ...

  5. VScode usage

    Common settings editor.minimap.enabled     //close the preview workbench.editor.show tabs  // show f ...

  6. Qtree1 - 树链剖分

    树剖裸题?(复习练练手) // luogu-judger-enable-o2 #include <bits/stdc++.h> using namespace std; ],size[], ...

  7. hive删除表时直接卡死

    原因:因为以前安装的mysql,字符集都改为了utf-8. 解决方案:需要把字符集都改为latin1 首先进入mysql查看字符集 show variables like 'char%' 找到mysq ...

  8. 关于List比较好玩的操作

    作为Java大家庭中的集合类框架,List应该是平时开发中最常用的,可能有这种需求,当集合中的某些元素符合一定条件时,想要删除这个元素.如: public class ListTest { publi ...

  9. JS变量和数据类型及其转化

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 浅析网页meta标签中X-UA-Compatible属性的使用

    今天有一个做开发的朋友突然问你知道很多网站上面加入的X-UA-Compatible属性的意义么?其实这个在以前还专门花了一点时间来验证我自己的想法,结果也确实如自己所预想的那样,八九不离十,当然有一点 ...