zoukankan      html  css  js  c++  java
  • 手把手教你搭建Docker私有仓库

    章节一:centos7 docker安装和使用_入门教程

    章节二:使用docker部署Asp.net core web应用程序

    有了前面的基础,接下来的操作就比较简单了。先准备两台虚拟机,两台机器上都配好yum源,安装好docker,设置好docker加速器。

    Docker客户端:192.168.1.160;Docker私有仓库服务器:192.168.1.161

    1.在服务端192.168.1.161上拉取仓库镜像:registry

    [root@localhost ~]# docker pull registry 

    2.在服务端192.168.1.161运行docker私有仓库

    [root@localhost ~]# docker run -d -v /registry:/var/lib/registry -p 5000:5000 --restart=always --privileged=true --name registry registry:latest

    如果成功执行,则表示我们的docker私有仓库搭建成功。

    下面对这条命令的部分内容做下说明。

    /registry表示宿主机目录,该目录如果不存在会自动创建。

    docker -v 宿主机目录:容器目录

    在网上看到的解释:

    把宿主机的目录挂载到容器中

    或者

    把docker 容器中某目录的数据 加载到 宿主机的某个目录

    这样做的目的是为了防止docker私有仓库这个容器被删除时,仓库里的镜像也会被删除。

    3.在客户端制作镜像

    以hello-world为例,先把它拉取下来

    [root@localhost ~]# docker pull hello-world

    给hello-world镜像打个tag,表示新的版本

    [root@localhost ~]# docker tag hello-world 192.168.1.161:5000/hello-world:latest 

    4.将新的hello-world镜像上传到私有仓库

    [root@localhost ~]# docker push 192.168.1.161:5000/hello-world:latest

    发现会报以下错误:

    The push refers to a repository [192.168.1.161:5000/hello-world]
    Get https://192.168.1.161:5000/v1/_ping: http: server gave HTTP response to HTTPS client

    原因是docker私有仓库服务器,默认是基于https传输的,所以我们需要在客户端192.168.1.160做相关设置,不使用https传输

    [root@localhost ~]# vi /etc/docker/daemon.json

    将下面的代码放进去保存并退出。

    "insecure-registries":["192.168.1.161:5000"]

    最终如下所示:

    {
            "registry-mirrors": ["https://njrds9qc.mirror.aliyuncs.com"],
            "insecure-registries":["192.168.1.161:5000"]
    }

    依次执行下面两条命令,重新启动docker:

    [root@localhost ~]# systemctl daemon-reload
    [root@localhost ~]# systemctl restart docker

    再次执行推送命令:

    [root@localhost ~]# docker push 192.168.1.161:5000/hello-world:latest

    5.在私有仓库192.168.1.161查看上传的镜像

    [root@localhost repositories]# ls /registry/docker/registry/v2/repositories

    或者在客户端执行以下命令查看:

    [root@localhost ~]# curl http://192.168.1.161:5000/v2/_catalog

    会输出:

    {"repositories":["hello-world"]}

    好,大功告成。

    参考地址:

    https://blog.csdn.net/mmd0308/article/details/77162004

    https://www.cnblogs.com/Javame/p/7389093.html

  • 相关阅读:
    Ubuntu下Geary安装
    (1)html初步--表格的使用
    MYSQL笔记
    三,springboot集成mybatis
    一台服务部署多个tomcat注意事项
    Apache和Tomcat整合(一个Apache 不同域名处理多个不同业务)
    linux 安装 apache
    linux笔记
    关联查询一张小表。对性能有影响吗(mysql)
    关于mysql的临时表并行的问题
  • 原文地址:https://www.cnblogs.com/subendong/p/9029495.html
Copyright © 2011-2022 走看看