本文介绍: 在 bootfs 之上的层级是 rootfsroot file system),它包含的是典型 Linux 系统中的 /dev、/proc、/bin、/etc标准目录和文化。联合文件系统是一种分层轻量级并且高性能文件系统,它支持文件系统修改作为一次提交来一层一层的叠加,同时可以不同目录挂载同一个虚拟文件系统下。Docker 镜像是 Docker 容器的基础,它提供了一种可重复使用的、跨平台部署方式,使得应用程序部署运行变得简单和高效。当容器启动时,一个新的可写层被加载镜像顶部

一、镜像概念

Docker 镜像是 Docker 容器的基础,它提供了一种可重复使用的、跨平台部署方式,使得应用程序部署运行变得简单和高效。

应用程序配置依赖打包好形成一个交付运行环境(包括代码运行需要的库、环境变量配置文件等),打包好的运行环境就是image镜像文件

 二、分层镜像

2.1 镜像的底层原理(联合文件系统)

Docker 镜像的底层原理是联合文件系统(UnionFS)。联合文件系统是一种分层轻量级并且高性能的文件系统,它支持对文件系统的修改作为一次提交来一层一层的叠加,同时可以不同目录挂载同一个虚拟文件系统下。

Docker 镜像实际上由一层一层的文件系统组成,这种层级的文件系统就是联合文件系统。在 Docker 镜像中,最底层引导文件系统(bootfs,它主要包含引导加载器和内核。当引导加载完成之后,整个内核就都在内存中了,此时内存使用权已由 bootfs 转交给内核,此时系统也会卸载 bootfs

bootfs 之上的层级是 rootfsroot file system),它包含的是典型 Linux 系统中的 /dev、/proc、/bin、/etc标准目录和文化。rootfs 就是各种不同操作系统发行版比如 Ubuntu、Centos 等。

联合文件系统使得 Docker 镜像可以分层进行继承基于基础镜像,可以制作各种具体的应用镜像。这种分层的好处是共享资源、方便复制迁移,从而能够提高效率,减少空间占用,方便维护更新

2.2 为什么docker镜像使用分层结构

Docker镜像层都是只读的,容器层是可写的。当容器启动时,一个新的可写层被加载到镜像的顶部。 这一层通常被称作“容器层”,“容器层”之下的都叫“镜像层”。

所有对容器的改动 。无论添加删除还是修改文件都只会发生在容器层中。只有容器层是可写的,容器层下面的所有镜像层都是只读的。
 

  三、docker镜像commit操作案例(重点)

 由此看出docker镜像分层,支通过现有的镜像,生成新的镜像,在原有基础上扩展

docker commit 提交容器副本使之成为一个新的镜像:

docker commit -m="提交的描述信息" -a="作者" 容器ID 要创建目标镜像名:[标签名]

示范:
docker commit -m="vim install ok" -a="syf" f49f1addd673  syf/mybuntun1.0

 如图ubuntu器中没有vim 命令

[root@syf ~]# docker run -it --name myubuntu ubuntu /bin/bash
root@f49f1addd673:/# ls
bin  boot  dev  etc  home  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@f49f1addd673:/# vim a.txt
bash: vim: command not found

安装vi

更新ubuntu管理工具
apt-get update
安装vim
apt-get -y install vim

 commit 我们安装vim 的ubuntu镜像

[root@syf ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS         PORTS     NAMES
f49f1addd673   ubuntu    "/bin/bash"   44 minutes ago   Up 5 minutes             myubuntu
[root@syf ~]# docker commit -m="vim install ok" -a="syf" f49f1addd673  syf/mybuntun1.0

查看结果

[root@syf ~]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED              SIZE
syf/mybuntun1.0   latest    5166bfe283d8   About a minute ago   189MB
tomcat            latest    fb5657adc892   23 months ago        680MB
redis             latest    7614ae9453d1   23 months ago        113MB
ubuntu            latest    ba6acccedd29   2 years ago          72.8MB

 四、阿里云镜像仓库创建

4.1今日阿里云,左上角菜单栏鼠标放上去展开搜索容器镜像服务

 4.2创建个人实例

4.3   创建命名空间

4.4在创建好的空间下,新建仓库 

4.5 选择本地仓库

最后阿里云会生成一堆命令copy使用就行。

五、阿里云镜像推送和拉去(重点)

5.1 先登录docker loginusername=测试账号 registry.cnshanghai.aliyuncs.com

[root@syf ~]# docker login --username=测试账号 registry.cn-shanghai.aliyuncs.com
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

5.2  打个tag

docker tag [ImageId] registry.cnshanghai.aliyuncs.com/ceshi_resposity/myubuntu:[镜像版本号]

[root@syf ~]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED         SIZE
syf/mybuntun1.0   latest    5166bfe283d8   2 hours ago     189MB
tomcat            latest    fb5657adc892   23 months ago   680MB
redis             latest    7614ae9453d1   23 months ago   113MB
ubuntu            latest    ba6acccedd29   2 years ago     72.8MB
[root@syf ~]# docker tag 5166bfe283d8 registry.cn-shanghai.aliyuncs.com/ceshi_resposity/myubuntu:1.0

 5.3  推送阿里仓库

docker push registry.cnshanghai.aliyuncs.com/ceshi_resposity/myubuntu:[镜像版本号]

[root@syf ~]# docker push registry.cn-shanghai.aliyuncs.com/ceshi_resposity/myubuntu:1.0

5.4从阿里云上拉去镜像 

docker pull registry.cnshanghai.aliyuncs.com/ceshi_resposity/myubuntu:[镜像版本号]

[root@syf ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
tomcat       latest    fb5657adc892   23 months ago   680MB
redis        latest    7614ae9453d1   23 months ago   113MB
ubuntu       latest    ba6acccedd29   2 years ago     72.8MB
[root@syf ~]# docker pull registry.cn-shanghai.aliyuncs.com/ceshi_resposity/myubuntu:1.0
1.0: Pulling from syf_resposity/myubuntu
7b1a6ab2e44d: Already exists 
1ec782c8d5e1: Pull complete 
Digest: sha256:c6d759583840a80c82c0704858b8c0f84e1daf5883db9521446f6cc8c1cc9ec0
Status: Downloaded newer image for registry.cn-shanghai.aliyuncs.com/syf_resposity/myubuntu:1.0
registry.cn-shanghai.aliyuncs.com/ceshi_resposity/myubuntu:1.0
[root@syf ~]# docker images
REPOSITORY                                                 TAG       IMAGE ID       CREATED         SIZE
registry.cn-shanghai.aliyuncs.com/syf_resposity/myubuntu   1.0       5166bfe283d8   2 hours ago     189MB
tomcat                                                     latest    fb5657adc892   23 months ago   680MB
redis                                                      latest    7614ae9453d1   23 months ago   113MB
ubuntu                                                     latest    ba6acccedd29   2 years ago     72.8MB

原文地址:https://blog.csdn.net/javaxueba/article/details/134647156

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_36108.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注