zoukankan      html  css  js  c++  java
  • 02:Docker镜像管理

    镜像管理:

    镜像是什么?

    • 一个分层存储的文件
    • 一个软件的环境
    • 一个镜像可以创建N个容器
    • 一种标准化的交付
    • 一个不包含Linux内核而又精简的Linux操作系统

    镜像不是一个单一的文件,而是有多层构成。我们可以通过docker history <ID/NAME> 查看镜像中各层内容及大小,每层对应着Dockerfile中的一条指令。Docker镜像默认存储在/var/lib/docker/<storage-driver>中。

    镜像从哪里来?
    Docker Hub是由Docker公司负责维护的公共注册中心,包含大量的容器镜像,Docker工具默认从这个公共镜像库下载镜像。
    地址:https://hub.docker.com/explore         使用:docker info命令并关注:Registry选项
    配置镜像加速器:https://www.daocloud.io/mirror

    curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
    [root@localhost overlay2]# cd /etc/docker/
    [root@localhost docker]# ls
    key.json
    [root@localhost docker]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
    docker version >= 1.12
    {"registry-mirrors": ["http://f1361db2.m.daocloud.io"]}
    Success.
    You need to restart docker to take effect: sudo systemctl restart docker 
    [root@localhost docker]# systemctl restart docker
    [root@localhost docker]# cat /etc/docker/daemon.json 
    {"registry-mirrors": ["http://f1361db2.m.daocloud.io"]}
    [root@localhost docker]#

    镜像与容器联系:

    如图,容器其实是在镜像的最上面加了一层读写层,在运行容器里文件改动时,会先从镜像里要写的文件复制到容器自己的文件系统中(读写层)。如果容器删除了,最上面的读写层也就删除了,改动也就丢失了。所以无论多少个容器共享一个镜像,所做的写操作都是从镜像的文件系统中复制过来操作的,并不会修改镜像的源文件,这种方式提高磁盘利用率。若想持久化这些改动,可以通过docker commit 将容器保存成一个新镜像。

    管理镜像常用命令:

    [root@localhost ~]# docker image --help
    
    Usage:    docker image COMMAND
    
    Manage images
    
    Commands:
      build       Build an image from a Dockerfile
      history     Show the history of an image
      import      Import the contents from a tarball to create a filesystem image
      inspect     Display detailed information on one or more images
      load        Load an image from a tar archive or STDIN
      ls          List images
      prune       Remove unused images
      pull        Pull an image or a repository from a registry
      push        Push an image or a repository to a registry
      rm          Remove one or more images
      save        Save one or more images to a tar archive (streamed to STDOUT by default)
      tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
    
    Run 'docker image COMMAND --help' for more information on a command.
    [root@localhost ~]# 

    可能要关注一下:ls、inspect、save和load,其他的稍微了解一下

  • 相关阅读:
    MVC HTTP 错误 403.14
    web.config connectionStrings 数据库连接字符串的解释(转载)
    bootstrap div 弹出与关闭
    jquery操作select(取值,设置选中)
    VS2013使用EF6与mysql数据库
    php中创建和调用webservice接口示例
    java script 确认框
    mysql中判断记录是否存在方法比较
    根据Unicode编码用C#语言把它转换成汉字的代码
    微软架构师解读Windows Server 2008 R2新特性
  • 原文地址:https://www.cnblogs.com/zheng-weimin/p/10264096.html
Copyright © 2011-2022 走看看