一、docker 常用操作及原理

  1、docker 常用操作

    

  2、docker 机制

    1、docker client端是通过http或者https与server端通信的。个

    2、docker 镜像可以认为是docker 集装箱

二、docker 镜像原理

  1、docker 镜像含有启动容器所需要的文件系统及其内容,因此其用于创建并启动docker 容器。

  2、docker 镜像采用分层构建机制,最底层为bootfs,上层为rootfs。

    a、bootfs,用于系统引导的文件系统,包括bootloader和kernel,容器启动完成后会被卸载以节约内存资源。

    b、rootfs,位于bootfs之上,表现为docker容器的根文件系统。

      1)、传统模式中,系统启动之时,内核挂载rootfs时会首先将其挂载为只读模式,完整性自检完成后将其重新挂载为读写模式。

      2)、docker中,rootfs由内核挂载为只读模式,而后通过联合挂载技术额外挂载一个可写层。

  3、原理图如图

    

  4、docker 镜像层

    a、位于下层的镜像称为父镜像,最底层的称为基础镜像。

    b、最上层为可读写层,其下的均为只读层。

    c、如图

      

三、docker 联合挂载的专用文件系统

  1、ubuntu 使用的联合挂载文件系统为aufs,centos使用的联合挂载文件系统为devicemapper,现在用的文件系统为overlayfs2。

  2、aufs一开始是UnionFS,后来因为UnionFS代码太烂了才重构了aufs,不过aufs代码也很烂

    

四、docker 镜像分类

  1、启动容器时,daemon会试图从本地获取相关的镜像,本地镜像不存在时,将从registry中下载该镜像并保存到本地。

    

  2、registry用于保存docker 镜像,包括镜像的层次结构和元数据。

  3、用户可自建registry,也可以用官方的docker hub

  4、分类

    

  5、repository和index

    

  6、docker registry中的镜像通常由开发人员制作,而后推送至公共或私有registry上保存供其它人员使用,例如部署到生产环境。

五、docker hub

  1、包含标签

    a、Image repositories:镜像仓库。

    b、Automated:自动构建。

    c、Webhooks(重要) !!!!!!!

      本地做的dockerfile 新版本文件推到github上,然后github上的变动会由webhooks被docker hub识别,然后docker hub将对应的dockerfile文件拿过去进行自动构建。

    d、Organizations:组织

    e、github and bitbucket integration:github 与 bitbucket进行整合。

      

  2、获取镜像(比较出名的镜像站点,quay.io)

    

  3、制作镜像

    a、dockerfile

    b、基于容器制作

    c、docker hub automated builds

      

六、镜像制作

  1、基于容器制作镜像,docker commit

[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
97054e941ebb d8233ab899d4 "sh" minutes ago Up minutes b1
[root@localhost ~]# docker commit 97054e941ebb busybox:b1
sha256:cd6c0da8b93f02715e30920112aae94f6c4d64815771a03c861e258b5f2c9a52
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox b1 cd6c0da8b93f seconds ago .2MB
busybox latest d8233ab899d4 weeks ago .2MB
nginx 1.14-alpine 66952fd0a8ef weeks ago 16MB
centos 721823ac0277 months ago 284MB

  2、docker commit 提交时添加作者名字和 默认启动参数

[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
121c36795a1d busybox:b1 "sh" minutes ago Up minutes test1
97054e941ebb d8233ab899d4 "sh" minutes ago Up minutes b1
[root@localhost ~]# docker commit -h
Flag shorthand -h has been deprecated, please use --help Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] Create a new image from a container's changes Options:
-a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
-c, --change list Apply Dockerfile instruction to the created image
-m, --message string Commit message
-p, --pause Pause container during commit (default true)
[root@localhost ~]# docker commit -a "lipingchang <1209989516@qq.com>" -m "this is a test" -c 'CMD ["/bin/httpd","-f","-h","/data/html"]' -p test1(容器名称) busybox:test1(制作的镜像名称)
sha256:f3847a399a98e54f1a3b283c06881d9adf98b663b17d92924272c251dc594c74

七、镜像的导入和导出

  1、docker save -o,将镜像打包保存为文件,可一次打包多个镜像。

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox test1 f3847a399a98 minutes ago .2MB
busybox b1 cd6c0da8b93f About an hour ago .2MB
busybox latest d8233ab899d4 weeks ago .2MB
nginx 1.14-alpine 66952fd0a8ef weeks ago 16MB
centos 721823ac0277 months ago 284MB
[root@localhost ~]# docker save -o busybox.gz busybox:test1 busybox:b1
[root@localhost ~]# ls
.txt anaconda-ks.cfg busybox.gz

  2、docker load -i,将打包后的镜像文件导入

[root@localhost ~]# docker rmi busybox:test1 busybox:b1
Untagged: busybox:test1
Deleted: sha256:f3847a399a98e54f1a3b283c06881d9adf98b663b17d92924272c251dc594c74
Deleted: sha256:8c8846e678a8952c6dce32aab80520b746732dda074f30843cdf0b9e89ea7cb2
Untagged: busybox:b1
Deleted: sha256:cd6c0da8b93f02715e30920112aae94f6c4d64815771a03c861e258b5f2c9a52
Deleted: sha256:1251dd6cc6ec2f2f0dbf3bef621bdb563834e99ba294b74054e6e5d5961c9536
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest d8233ab899d4 weeks ago .2MB
nginx 1.14-alpine 66952fd0a8ef weeks ago 16MB
centos 721823ac0277 months ago 284MB
quay.io/coreos/flannel v0.10.0-amd64 f0fad859c909 months ago .6MB
[root@localhost ~]# docker load --help Usage: docker load [OPTIONS] Load an image from a tar archive or STDIN Options:
-i, --input string Read from tar archive file, instead of STDIN
-q, --quiet Suppress the load output
[root@localhost ~]# docker load -i busybox.gz
e703b81e02e8: Loading layer [==================================================>] .608kB/.608kB
6321d48b6459: Loading layer [==================================================>] .56kB/.56kB
Loaded image: busybox:test1
Loaded image: busybox:b1
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox test1 f3847a399a98 About an hour ago .2MB
busybox b1 cd6c0da8b93f About an hour ago .2MB
busybox latest d8233ab899d4 weeks ago .2MB
nginx 1.14-alpine 66952fd0a8ef weeks ago 16MB
centos 721823ac0277 months ago 284MB
quay.io/coreos/flannel v0.10.0-amd64 f0fad859c909 months ago .6MB

  3、将容器导出为镜像文件

[root@localhost ~]# docker run -itd --name test1 busybox:test1 /bin/sh
075377828bfec54ff41d17d75da06e970189e1a0616a54f12fb25be12e170da2
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
075377828bfe busybox:test1 "/bin/sh" seconds ago Up seconds test1
[root@localhost ~]# docker export 075377828bfe > update.tar
[root@localhost ~]# ls
.txt anaconda-ks.cfg update.tar

  4、将容器导出的镜像文件导入为镜像

[root@localhost ~]# docker import - import < update.tar
sha256:5d0d74a05a0f75486c817f0efe47072ff34bfecb1f4175daf588050b2cacc6bb
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
import latest 5d0d74a05a0f seconds ago .2MB
busybox test1 f3847a399a98 About an hour ago .2MB
busybox b1 cd6c0da8b93f About an hour ago .2MB
busybox latest d8233ab899d4 weeks ago .2MB
nginx 1.14-alpine 66952fd0a8ef weeks ago 16MB
centos 721823ac0277 months ago 284MB
quay.io/coreos/flannel v0.10.0-amd64 f0fad859c909 months ago .6MB

  

    

Docker 学习3 Docker镜像管理基础的更多相关文章

  1. docker第三篇 镜像管理基础

    docker 工作原理: 常用的命令docker run .create .start... 都是客户端命令 Docker Daemon 接收到客户端传过来的命令以后 docker daemon会根据 ...

  2. Docker镜像管理基础篇

    Docker镜像管理基础篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Docker Images Docker镜像还有启动容器所需要的文件系统及其内容,因此,其用于创建并启 ...

  3. Docker学习之Docker镜像基本使用

    Docker学习之Docker镜像基本使用 获取镜像 命令格式:docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签] 例如: docker pull ...

  4. Docker学习笔记 — Docker私有仓库搭建

    Docker学习笔记 — Docker私有仓库搭建   目录(?)[-] 环境准备 搭建私有仓库 测试 管理仓库中的镜像 查询 删除 Registry V2   和Mavan的管理一样,Dockers ...

  5. Docker学习之Docker容器基本使用

    Docker学习之Docker容器基本使用 新建容器并启动 命令格式:docker run --options repository:tag 后台运行 命令格式:-d 已存在的容器相关操作 启动:do ...

  6. 3、Docker镜像管理基础

    Docker image     # docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE redis -alpine 23d561d12e92 d ...

  7. Docker镜像管理基础与基于容器的镜像制作示例

    一.Docker镜像 Docker镜像是启动Docker容器的一个非常重要的组件.Docker各组件之间的关系如图: Docker镜像含有启动容器所需要的文件系统及其内容,因此Docker镜像用于创建 ...

  8. DOCKER学习_009:Docker的镜像管理

    1 查看镜像 [root@docker-server3 ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE redis days ago ...

  9. Docker学习笔记之创建Ubuntu基础镜像

    在创建基础镜像之前需要安装Bootstrap工具debootstrap,所以执行命令: sudo apt install debootstrap 软件安装完成后就可以使用debootstrap工具下载 ...

随机推荐

  1. codeforces-1131 (div2)

    A.把右上角的凹缺口补上变成凸的就成了规则矩形 #include <map> #include <set> #include <ctime> #include &l ...

  2. guns初级使用

    1.下载guns gitee地址:https://gitee.com/stylefeng/guns 这里使用的是Guns v5.1 2.配置环境 2.1 导入项目 解压从gitee上下载的guns源码 ...

  3. Jmeter工具进行一个完整的接口测试

    Jmeter工具进行一个完整的接口测试 1.创建一个线程组 通俗的讲一个线程组,,可以看做一个虚拟用户组,线程组中的每个线程都可以理解为一个虚拟用户.   2.输入线程组名字 3.添加一个cookie ...

  4. [面试] Java GC (未整理完)

    Java GC简介 什么是 GC ? Java程序不用像C++程序在程序中自行处理内存的回收释放.这是因为Java在JVM虚拟机上增加了垃圾回收(GC)机制,用以在合适的时间触发垃圾回收. 你都了解哪 ...

  5. [面试]StringBuilder StringBuffer源码粘贴(并非源码分析, 请绕道)

    StringBuilder StringBuffer 源码 这里只是我个人笔记, 并没有在这篇文章里做任何技术分享, 请同学们绕道- -.如果需要我会后期补上的..... 本来是想分析源码来着, 但是 ...

  6. react动态路由以及获取动态路由

    业务中会遇到点击列表跳转到详情页, 1.在index.js修改我们的跟组件 新建router2的文件 import React from 'react' import { HashRouter as ...

  7. JavaScript之iframe页面间通信

    [1] iframe父子页面间通信 1.相互调用对方的方法 |> 子级页面调用父级页面 window.parent.父级页面方法(args) |> 父级页面调用子级页面 document. ...

  8. git错误记录及解决

    一.git每次提交.拉取都要输用户名和密码 问题描述:每次提交.拉取文件时都要输用户名和密码,特别麻烦 原因:在git上面注册了用户名a,然后本机安装了TortoiseGit工具,登录时会在本机C:\ ...

  9. Win2012 R2安装 mysql8.0

    1.官网下载安装 官网上面写着x86,其实是兼容x64和x86的,下载安装就行 2.安装navicat 3.navicat连接mysql的时候出现错误 client does not support ...

  10. 【转】pyhton之Reportlab模块——生成pdf文件

    [转]pyhton之Reportlab模块 reportlab模块是用python语言生成pdf文件的模块 安装:pip install reportlab 模块默认不支持中文,如果使用中文需要注册 ...