一起学docker(三)| portainer + 镜像加载原理 + 发布镜像

portainer(了解)

一个图形化界面管理工具!!!

安装
docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer
访问

ip:8080

第一次访问需要创建账户!

一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第1张图片

一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第2张图片

一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第3张图片

Docker 镜像

是什么

镜像是一种轻量级、可执行的独立软件包,用来打包软件运行环境和基于环境开发的软件,它包含运行某个软件所需的所有内容,包括代码、运行时(库、环境变量和配置文件)。所有的应用,直接打包docker镜像,就可以跑起来!

镜像加载原理
UnionFS(联合文件系统)

UnionFS是一种分层、轻量级并且高性能的文件系统,它支持对文件系统的修改作为一次提交来一层层的叠加,同时可以将不同目录挂载到同一个虚拟文件系统下(unite several directories into single virtual filesystem)。UnionFS是Docker镜像的基础,镜像可以通过分层来继承,基于基础镜像(没有父镜像),可以制作各种具体的镜像。

特性:

一次同时加载多个文件系统,但从外面看起来,只能看到一个文件系统,联合加载会把各层文件系统叠加起来,这样最终的文件系统会包含所有底层的文件和目录。

Docker镜像加载原理

Docker的镜像实际上由一层一层的文件系统组成,这种层级的文件系统就是UnionFS。

bootfs(boot file system)主要包含bootloader和kernel,bootloader主要是引导加载kernel,Linux刚启动时会加载bootfs文件系统,在Docker镜像最底层是bootfs。这一层与我们典型的Linux/Unix系统是一样的,包含boot加载器和内核。当boot加载完成之后整个内核就都在内存中了,此时内存的使用权已由bootfs转交给内核,此时系统也会卸载bootfs。

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

一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第4张图片

平时安装进虚拟机的centos很大,镜像都是几个G,但是Docker里仅仅231MB!!!

[root@VM-4-9-centos ~]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
hello-world           latest    9c7a54a9a43c   2 months ago    13.3kB
portainer/portainer   latest    5f11582196a4   8 months ago    287MB
centos                latest    5d0da3dc9764   22 months ago   231MB

对于一个精简的OS,rootfs可以很小,只需要包含最基本的命令、工具和程序库就可以了。因为底层直接用Host的kernel,自己只需要提供rootfs即可。由此可见,对于不同的Linux发行版,bootfs基本是一致的,rootfs会有差别,因此不同的发行版可以共用bootfs。

虚拟机是分钟级别,Docker容器是秒级!!!

分层理解

我们去拉取下载一个镜像,注意下载日志,可以看到是一层一层的下载!

[root@VM-4-9-centos ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
faef57eae888: Already exists 
76579e9ed380: Pull complete 
cf707e233955: Pull complete 
91bb7937700d: Pull complete 
4b962717ba55: Pull complete 
f46d7b05649a: Pull complete 
103501419a0a: Pull complete 
Digest: sha256:08bc36ad52474e528cc1ea3426b5e3f4bad8a130318e3140d6cfe29c8892c7ef
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@VM-4-9-centos ~]# 

Docker镜像为何采用分层结构???

  • 资源共享。如有多个镜像都从相同的Base镜像构建而来,那么宿主机只需在磁盘上保留一份base镜像,同时内存中也只需要加载一份base镜像。这样就可以为所有的容器服务了,而且镜像的每一层都可共享。
[root@VM-4-9-centos ~]# docker inspect nginx
[
    {
        "Id": "sha256:021283c8eb95be02b23db0de7f609d603553c6714785e7a673c6594a624ffbda",
        "RepoTags": [
            "nginx:latest"
        ],
        "RepoDigests": [
            "nginx@sha256:08bc36ad52474e528cc1ea3426b5e3f4bad8a130318e3140d6cfe29c8892c7ef"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2023-07-04T17:24:26.955102691Z",
        "Container": "1202d20005c45c16a7c97a3e50ae2a74113557f6645062e78797c946247d12e3",
        "ContainerConfig": {
            "Hostname": "1202d20005c4",
        ......
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:24839d45ca455f36659219281e0f2304520b92347eb536ad5cc7b4dbb8163588",
                "sha256:b821d93f6666533e9d135afb55b05327ee35823bb29014d3c4744b01fc35ccc5",
                "sha256:1998c5cd2230129d55a6d8553cd57df27a400614a4d7d510017467150de89739",
                "sha256:f36897eea34df8a4bfea6e0dfaeb693eea7654cd7030bb03767188664a8a7429",
                "sha256:9fdfd12bc85b7a97fef2d42001735cfc5fe24a7371928643192b5494a02497c1",
                "sha256:434c6a715c30517afd50547922c1014d43762ebbc51151b0ecee9b0374a29f10",
                "sha256:3c9d04c9ebd5324784eb9a556a7507c5284aa7353bac7a727768fed180709a69"
            ]
        ......
    }
]
[root@VM-4-9-centos ~]# 

**所有的Docker镜像都起始于一个基础镜像层,当进行修改或增加新的内容时,就会在当前镜像层之上,创建新的镜像层。**举一个简单的例子,如基于Ubuntu Linux 16.04创建一个新的镜像,这就是新镜像的第一层;如果在该镜像中添加Python包,就会在基础镜像层之上创建第二个镜像层;如果再继续添加一个安全补丁,就会再创建第三个镜像层。

一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第5张图片

在添加额外的镜像层的同时,镜像始终保持是当前所有镜像的组合!!!

如每个镜像包含3个文件,而镜像包含了来自两个镜像层的6个文件。

一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第6张图片

这种情况下,上层镜像层中的文件覆盖了底层镜像层中的文件。这样就使得文件的更新版本作为一个新镜像层添加到镜像中。

Docker通过存储引擎(新版本采用快照机制)的方式来实现镜像层堆栈,并保证多镜像层对外展示为统一的文件系统。

Linux上可用的存储引擎有AUFS、Overlay2、Device Mapper、Btrfs及ZFS。顾名思义,每种存储引擎都基于Linux中对应的文件系统或者块设备技术,并且每种存储引擎都有其独有的性能特点。

Docker在Windows上仅支持windowsfilter一种存储引擎,该引擎基于NTFS文件系统之上实现了分层和CoW。

下图展示了与系统显示相同的三层镜像。所有镜像层堆叠合并,对外提供统一的视图。

一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第7张图片

特点:

Docker镜像都是只读的,当容器启动时,一个新的可写层被加载到镜像的顶部。

这一层就是我们常说的容器层,容器之下的都叫镜像层。

一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第8张图片

commit镜像

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

docker commit -m="add webapps application" -a="jiang" eb92a5483eb2 tomcat-j:1.0

tomcat案例:

  1. 新建容器并启动
[root@VM-4-9-centos ~]# docker run -d -p 8088:8080 tomcat
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /opt/java/openjdk
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
25-Jul-2023 02:58:46.110 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/10.1.11
......
  1. 访问报错404,进入webapps下发现没有,从webapps.dist下cp过去
[root@VM-4-9-centos ~]# docker exec -it eb92a5483eb2 /bin/bash
root@eb92a5483eb2:/usr/local/tomcat# ls
bin  BUILDING.txt  conf  CONTRIBUTING.md  lib  LICENSE  logs  native-jni-lib  NOTICE  README.md  RELEASE-NOTES  RUNNING.txt  temp  webapps  webapps.dist  work
root@eb92a5483eb2:/usr/local/tomcat# ls webapps
root@eb92a5483eb2:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@eb92a5483eb2:/usr/local/tomcat# ls webapps
docs  examples  host-manager  manager  ROOT
root@eb92a5483eb2:/usr/local/tomcat# 
  1. 可以正常访问

一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第9张图片

  1. 想保存这样的一个tomcat快照,可以将其commit
[root@VM-4-9-centos ~]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
mysql                 latest    f6360852d654   3 days ago      565MB
redis                 latest    7e89539dd8bd   13 days ago     130MB
tomcat                latest    95f422fe411b   2 weeks ago     475MB
nginx                 latest    021283c8eb95   2 weeks ago     187MB
hello-world           latest    9c7a54a9a43c   2 months ago    13.3kB
portainer/portainer   latest    5f11582196a4   8 months ago    287MB
centos                latest    5d0da3dc9764   22 months ago   231MB
[root@VM-4-9-centos ~]# docker ps
CONTAINER ID   IMAGE     COMMAND             CREATED          STATUS          PORTS                                       NAMES
eb92a5483eb2   tomcat    "catalina.sh run"   13 minutes ago   Up 13 minutes   0.0.0.0:8088->8080/tcp, :::8088->8080/tcp   vigorous_tu
03351a0e8a6a   centos    "/bin/bash"         20 hours ago     Up 19 hours                                                 centos
[root@VM-4-9-centos ~]# docker commit -m="add webapps application" -a="jiang" eb92a5483eb2 tomcat-j:1.0
sha256:f1349e14e065899d340725d2e771463868b59591abdeca0f8c3847011b45b453
[root@VM-4-9-centos ~]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED          SIZE
tomcat-j              1.0       f1349e14e065   10 seconds ago   479MB
mysql                 latest    f6360852d654   3 days ago       565MB
redis                 latest    7e89539dd8bd   13 days ago      130MB
tomcat                latest    95f422fe411b   2 weeks ago      475MB
nginx                 latest    021283c8eb95   2 weeks ago      187MB
hello-world           latest    9c7a54a9a43c   2 months ago     13.3kB
portainer/portainer   latest    5f11582196a4   8 months ago     287MB
centos                latest    5d0da3dc9764   22 months ago    231MB
[root@VM-4-9-centos ~]# 

我们就得到了一个需要的tomcat镜像!!!

发布镜像

本地镜像发布到dockerhub
  1. 登录docker login -u 用户名

    [root@VM-4-9-centos dockerfile]# docker login -u mingdajiang
    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
    [root@VM-4-9-centos dockerfile]# 
    
  2. 规范TAG,加上dockerhub登录名docker tag 镜像名:Tag 用户名/目标镜像名:Tag

    [root@VM-4-9-centos dockerfile]# docker tag mytomcat:1.0 mingdajiang/mytomcat:1.0
    [root@VM-4-9-centos dockerfile]# docker images
    REPOSITORY                    TAG                 IMAGE ID       CREATED          SIZE
    mytomcat                      1.0                 85a142640f0d   15 minutes ago   837MB
    mingdajiang/mytomcat          1.0                 85a142640f0d   15 minutes ago   837MB
    mycentos                      1.0                 b7a758d3704a   2 hours ago      666MB
    121.4.126.115:5000/ubuntu-j   1.0                 f706429da9df   2 weeks ago      186MB
    
  3. 推送docker push 用户名/镜像名:Tag

    [root@VM-4-9-centos dockerfile]# docker push mingdajiang/mytomcat:1.0
    The push refers to repository [docker.io/mingdajiang/mytomcat]
    5f70bf18a086: Pushed 
    b50f79024f50: Pushed 
    eb0e46984efb: Pushed 
    2caa0de43df6: Pushed 
    174f56854903: Pushed 
    1.0: digest: sha256:f9a8c3d33ee39fb6015da344f0a897c3568f4a613af6794b02d21dc15277da9d size: 1372
    [root@VM-4-9-centos dockerfile]# 
    
本地镜像发布到阿里云

流程:

一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第10张图片

  1. 登录阿里云,找到容器镜像服务,进入个人实例

  2. 新建命名空间

    一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第11张图片

  3. 新建镜像仓库

    一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第12张图片

  4. 进入仓库,查看指南

    一起学docker(三)| portainer + 镜像加载原理 + 发布镜像_第13张图片

  5. 登录阿里云docker login --username=jiangmingda registry.cn-hangzhou.aliyuncs.com

    [root@VM-4-9-centos ~]# docker login --username=jiangmingda registry.cn-hangzhou.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
    [root@VM-4-9-centos ~]# 
    
  6. 选取镜像docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat:[镜像版本号]

    [root@VM-4-9-centos ~]# docker images
    REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
    jiang/tom             v2.0      92c249ed74a4   16 hours ago    477MB
    tomcat-j              1.0       f1349e14e065   23 hours ago    479MB
    mysql                 latest    f6360852d654   4 days ago      565MB
    redis                 latest    7e89539dd8bd   2 weeks ago     130MB
    tomcat                latest    95f422fe411b   2 weeks ago     475MB
    nginx                 latest    021283c8eb95   3 weeks ago     187MB
    hello-world           latest    9c7a54a9a43c   2 months ago    13.3kB
    portainer/portainer   latest    5f11582196a4   8 months ago    287MB
    centos                latest    5d0da3dc9764   22 months ago   231MB
    [root@VM-4-9-centos ~]# docker tag 92c249ed74a4 registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat:2.0
    [root@VM-4-9-centos ~]# 
    
  7. 推送docker push registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat:[镜像版本号]

    [root@VM-4-9-centos ~]# docker push registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat:2.0
    The push refers to repository [registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat]
    91f82e90e63a: Pushed 
    2.0: digest: sha256:e91d9c88547dfd0aa5a6b7a891b3e21aea237c962df7c8387b8e71a2a0854306 size: 529
    [root@VM-4-9-centos ~]# 
    

将阿里云上的镜像下载到本地

docker pull registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat:[镜像版本号]

[root@VM-4-9-centos ~]# docker images
REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
mysql                 latest    f6360852d654   4 days ago      565MB
redis                 latest    7e89539dd8bd   2 weeks ago     130MB
nginx                 latest    021283c8eb95   3 weeks ago     187MB
hello-world           latest    9c7a54a9a43c   2 months ago    13.3kB
portainer/portainer   latest    5f11582196a4   8 months ago    287MB
centos                latest    5d0da3dc9764   22 months ago   231MB
[root@VM-4-9-centos ~]# docker pull registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat:2.0
2.0: Pulling from jiang-da/mytomcat
058c3e20f6f1: Pull complete 
Digest: sha256:e91d9c88547dfd0aa5a6b7a891b3e21aea237c962df7c8387b8e71a2a0854306
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat:2.0
registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat:2.0
[root@VM-4-9-centos ~]# docker images
REPOSITORY                                            TAG       IMAGE ID       CREATED         SIZE
registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat   2.0       92c249ed74a4   16 hours ago    477MB
mysql                                                 latest    f6360852d654   4 days ago      565MB
redis                                                 latest    7e89539dd8bd   2 weeks ago     130MB
nginx                                                 latest    021283c8eb95   3 weeks ago     187MB
hello-world                                           latest    9c7a54a9a43c   2 months ago    13.3kB
portainer/portainer                                   latest    5f11582196a4   8 months ago    287MB
centos                                                latest    5d0da3dc9764   22 months ago   231MB
本地镜像发布到私有库
  • 官方Docker Hub地址:https://hub.docker.com/,中国大陆访问太慢了且准备被阿里云取代的趋势,不太主流。

  • Dockerhub、阿里云这样的公共镜像仓库可能不太方便,涉及机密的公司不可能提供镜像给公网,所以需要创建一个本地私人仓库供给团队使用,基于公司内部项目构建镜像。

Docker Registry是官方提供的工具,可以用于构建私有镜像仓库

将本地镜像推送到私有库:

  1. 下载镜像docker pull registry

    [root@VM-4-9-centos ~]# docker pull registry
    Using default tag: latest
    latest: Pulling from library/registry
    79e9f2f55bf5: Pull complete 
    0d96da54f60b: Pull complete 
    5b27040df4a2: Pull complete 
    e2ead8259a04: Pull complete 
    3790aef225b9: Pull complete 
    Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
    Status: Downloaded newer image for registry:latest
    docker.io/library/registry:latest
    [root@VM-4-9-centos ~]# 
    
  2. 运行私有库registry,相当于本地有个私有的dockerhubdocker run -d -p 5000:5000 -v /jmd/myregistry/:/tmp/registry --privileged=true registry

    [root@VM-4-9-centos ~]# docker run -d -p 5000:5000 -v /jmd/myregistry/:/tmp/registry --privileged=true registry
    f5346aab90632d8286139d05fed4933b34e513dfdba31727b51ebf8f9f51206b
    [root@VM-4-9-centos ~]# docker ps
    CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS          PORTS                                       NAMES
    f5346aab9063   registry   "/entrypoint.sh /etc…"   4 seconds ago    Up 3 seconds    0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   ecstatic_goldwasser
    02f5fb3787cf   tomcat     "catalina.sh run"        20 minutes ago   Up 20 minutes   0.0.0.0:8088->8080/tcp, :::8088->8080/tcp   tomcat10
    [root@VM-4-9-centos ~]# 
    
  3. (可选)创建一个新镜像,ubuntu安装vim和ifconfig命令

    [root@VM-4-9-centos ~]# docker run -it ubuntu /bin/bash
    root@a247ec8776ca:/# vim test.txt
    bash: vim: command not found
    root@a247ec8776ca:/# ifconfig
    bash: ifconfig: command not found
    root@a247ec8776ca:/# apt-get update   # 更新包管理工具
    Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
    ......
    ......
    root@a247ec8776ca:/# apt-get -y install vim  # 安装vim
    Reading package lists... Done
    ......
    ......
    root@a247ec8776ca:/# apt-get -y install net-tools  安装ifconfig
    Reading package lists... Done
    ......
    ......
    root@a247ec8776ca:/# vim test.txt
    root@a247ec8776ca:/# ls
    bin  boot  dev  etc  home  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  test.txt  tmp  usr  var
    root@a247ec8776ca:/# ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 172.17.0.4  netmask 255.255.0.0  broadcast 172.17.255.255
            ether 02:42:ac:11:00:04  txqueuelen 0  (Ethernet)
            RX packets 8910  bytes 43411001 (43.4 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 8346  bytes 572163 (572.1 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    root@a247ec8776ca:/# 
    
  4. commit镜像docker commit -m="a提交的信息" -a="作者" 容器id 要创建的目标镜像名:标签名

    [root@VM-4-9-centos ~]# docker ps
    CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS          PORTS                                       NAMES
    a247ec8776ca   ubuntu     "/bin/bash"              11 minutes ago   Up 11 minutes                                               tender_margulis
    f5346aab9063   registry   "/entrypoint.sh /etc…"   15 minutes ago   Up 15 minutes   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   ecstatic_goldwasser
    02f5fb3787cf   tomcat     "catalina.sh run"        36 minutes ago   Up 36 minutes   0.0.0.0:8088->8080/tcp, :::8088->8080/tcp   tomcat10
    [root@VM-4-9-centos ~]# docker commit -m="add vim,ifconfig to ubuntu" -a="jmd" a247ec8776ca ubuntu-j:1.0
    sha256:f706429da9df44702f2f8b8a00756c539afb76a451927c9fb033626aa936e60e
    [root@VM-4-9-centos ~]# docker images
    REPOSITORY                                            TAG       IMAGE ID       CREATED         SIZE
    ubuntu-j                                              1.0       f706429da9df   8 seconds ago   186MB
    registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat   2.0       92c249ed74a4   18 hours ago    477MB
    mysql                                                 latest    f6360852d654   4 days ago      565MB
    redis                                                 latest    7e89539dd8bd   2 weeks ago     130MB
    nginx                                                 latest    021283c8eb95   3 weeks ago     187MB
    hello-world                                           latest    9c7a54a9a43c   2 months ago    13.3kB
    portainer/portainer                                   latest    5f11582196a4   8 months ago    287MB
    tomcat                                                latest    fb5657adc892   19 months ago   680MB
    registry                                              latest    b8604a3fe854   20 months ago   26.2MB
    ubuntu                                                latest    ba6acccedd29   21 months ago   72.8MB
    centos                                                latest    5d0da3dc9764   22 months ago   231MB
    [root@VM-4-9-centos ~]# 
    
  5. curl查看私服库上有什么镜像curl -XGET http://121.4.126.115:5000/v2/_catalog

    [root@VM-4-9-centos ~]# curl -XGET http://121.4.126.115:5000/v2/_catalog
    {"repositories":[]}
    [root@VM-4-9-centos ~]# 
    
  6. 将镜像修改符合私服规范的Tagdocker tag 镜像:Tag Host:Port/Repository:Tag

    [root@VM-4-9-centos ~]# docker tag ubuntu-j:1.0 121.4.126.115:5000/ubuntu-j:1.0
    [root@VM-4-9-centos ~]# docker images
    REPOSITORY                                            TAG       IMAGE ID       CREATED          SIZE
    121.4.126.115:5000/ubuntu-j                           1.0       f706429da9df   23 minutes ago   186MB
    ubuntu-j                                              1.0       f706429da9df   23 minutes ago   186MB
    registry.cn-hangzhou.aliyuncs.com/jiang-da/mytomcat   2.0       92c249ed74a4   18 hours ago     477MB
    mysql                                                 latest    f6360852d654   4 days ago       565MB
    redis                                                 latest    7e89539dd8bd   2 weeks ago      130MB
    nginx                                                 latest    021283c8eb95   3 weeks ago      187MB
    hello-world                                           latest    9c7a54a9a43c   2 months ago     13.3kB
    portainer/portainer                                   latest    5f11582196a4   8 months ago     287MB
    tomcat                                                latest    fb5657adc892   19 months ago    680MB
    registry                                              latest    b8604a3fe854   20 months ago    26.2MB
    ubuntu                                                latest    ba6acccedd29   21 months ago    72.8MB
    centos                                                latest    5d0da3dc9764   22 months ago    231MB
    [root@VM-4-9-centos ~]# 
    
  7. docker默认不允许http方式推送镜像,通过配置选项来取消这个限制(不生效重启docker)

    • vim /etc/docker/daemon.json
    • {
      “registry-mirrors”: [“https://t01llloc.mirror.aliyuncs.com”],
      “insecure-registries”: [“121.4.126.115:5000”]
      }
  8. 推送镜像到私有库docker push 121.4.126.115:5000/ubuntu-j:1.0

    [root@VM-4-9-centos ~]# docker push 121.4.126.115:5000/ubuntu-j:1.0
    The push refers to repository [121.4.126.115:5000/ubuntu-j]
    6b9dc6df7e5c: Pushed 
    9f54eef41275: Pushed 
    1.0: digest: sha256:75a73b80d4ce590d248c49a5fb3c74066e0ad93e85eee1afb8e066232456a210 size: 741
    
  9. 查看是否推送到私有库上curl -XGET http://121.4.126.115:5000/v2/_catalog

    [root@VM-4-9-centos ~]# curl -XGET http://121.4.126.115:5000/v2/_catalog
    {"repositories":["ubuntu-j"]}
    
  10. pull到本地docker pull 121.4.126.115:5000/ubuntu-j:1.0

    [root@VM-4-9-centos ~]# docker images
    REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
    mysql                 latest    f6360852d654   4 days ago      565MB
    redis                 latest    7e89539dd8bd   2 weeks ago     130MB
    nginx                 latest    021283c8eb95   3 weeks ago     187MB
    hello-world           latest    9c7a54a9a43c   2 months ago    13.3kB
    portainer/portainer   latest    5f11582196a4   8 months ago    287MB
    tomcat                latest    fb5657adc892   19 months ago   680MB
    registry              latest    b8604a3fe854   20 months ago   26.2MB
    centos                latest    5d0da3dc9764   22 months ago   231MB
    [root@VM-4-9-centos ~]# docker pull 121.4.126.115:5000/ubuntu-j:1.0
    1.0: Pulling from ubuntu-j
    7b1a6ab2e44d: Already exists 
    b33e534b73ca: Already exists 
    Digest: sha256:75a73b80d4ce590d248c49a5fb3c74066e0ad93e85eee1afb8e066232456a210
    Status: Downloaded newer image for 121.4.126.115:5000/ubuntu-j:1.0
    121.4.126.115:5000/ubuntu-j:1.0
    [root@VM-4-9-centos ~]# docker images
    REPOSITORY                    TAG       IMAGE ID       CREATED         SIZE
    121.4.126.115:5000/ubuntu-j   1.0       f706429da9df   3 hours ago     186MB
    mysql                         latest    f6360852d654   4 days ago      565MB
    redis                         latest    7e89539dd8bd   2 weeks ago     130MB
    nginx                         latest    021283c8eb95   3 weeks ago     187MB
    hello-world                   latest    9c7a54a9a43c   2 months ago    13.3kB
    portainer/portainer           latest    5f11582196a4   8 months ago    287MB
    tomcat                        latest    fb5657adc892   19 months ago   680MB
    registry                      latest    b8604a3fe854   20 months ago   26.2MB
    centos                        latest    5d0da3dc9764   22 months ago   231MB
    [root@VM-4-9-centos ~]# 
    

你可能感兴趣的:(docker,docker,容器,运维)