实验环境

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. H5_0015:判断是否是微信加载

        var e = document.createElement("script");     e.src = "https://res.wx.qq.com/open ...

  2. 【大道至简】NetCore3.1快速开发框架一:集成Swagger

    在上一章节中,我们创建了基本的框架结构:https://www.cnblogs.com/fuyu-blog/p/12217647.html 下面我们测试接口和集成Swagger接口文档 一.接口测试 ...

  3. Scrum简介

    1. 什么是Scrum Scrum是一种轻量级的框架,适合于小型的.结合紧密的团队开发复杂的产品.Scrum是二十世纪后期一些软件工程师协同努力的脑力劳动的成果,现已成为技术领域最具魅力的方法.但Sc ...

  4. CSS的列表样式和网页背景

    CSS的列表样式 1. 设置title和列表 HTML: <!DOCTYPE html><html lang="en"><head>    &l ...

  5. 在vue项目中使用MD5.js

    1.安装 npm install --save js-md5 2.引入 import md5 from 'js-md5'; 3.使用 md5('holle') // bcecb35d0a12baad4 ...

  6. 微信小程序中如何上传图片

    本篇文章给大家带来的内容是关于微信小程序中如何上传图片(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 一.wxml文件 <text>上传图片</text ...

  7. 【python&pycharm的安装使用】

    一.Python3.7安装 1. 运行python3.7.exe 2. 检查是否安装成功:命令窗口输入python -V 二.Pycharm安装 1. 运行pycharm.exe(社区版) 2. 配置 ...

  8. Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type

    问题描述 将项目挂载到 Myeclipse 的 tomcat 上,启动 tomcat ,报错“Initialization of bean failed; nested exception is ja ...

  9. 【转】Java(多)线程中注入Spring的Bean

    问题说明 今天在web应用中用到了Java多线程的技术来并发处理一些业务,但在执行时一直会报NullPointerException的错误,问题定位了一下发现是线程中的Spring bean没有被注入 ...

  10. 题解 P5613 【[MtOI2019]黑蚊子多】

    题目传送门 一道模拟题目,签到送分题. 您需要的知识 1.while循环 2.for循环 3.一维数组 思路: Step 1:按题目要求,定义a[],n,m,k int a[10001]; int n ...