zoukankan      html  css  js  c++  java
  • docker学习(8) 在mac机上搭建私有仓库

    docker的私有仓库类似maven的私服,一般用于公司内部搭建一个类似docker hub的环境,这样上传、下载镜像速度较快,本文将演示如何在mac上利用docker-machine搭建无需SSL证书的私有仓库。

    一、查看docker-machine虚拟机IP

    docker-machine ip default
    

    默认情况下docker-toolbox创建的虚拟机名称为default,如果您的虚拟机名字不是这个,上面命令最后的default换成真实的虚拟机名字,假设default分配的IP为192.168.99.100

    二、修改虚拟机中的docker启动配置

    由于docker最新版本默认访问私服时,强制采用SSL安全连接,但一般内部应用时不需要这么高的安全级别,参考下面的做法降低安全设置:

    docker-machine ssh default
    sudo vi /var/lib/boot2docker/profile

    在profile文件最后加上:

    EXTRA_ARGS="--insecure-registry 192.168.99.100:5000"
    

    然后exit退出default,输入以下命令重启虚拟机

    docker-machine restart default
    

    三、创建私服容器

    dao pull registry 
    
    docker run -d -p 5000:5000 --restart=always -h registry 
     --name registry 
     -v /Users/yjmyzz/data/registry:/tmp/registry 
     registry
    

    第1行的dao pull registry表示将从daocloud.io上拉取registry镜像,如果本机已经有该镜像,可以省略。

    -v 后面的路径,大家改成实际路径,这个目录用于存放push到私有仓库的images文件。

    四、测试上传、下载

    4.1 先从daocloud.io上拉一个hello-world

    hello-world这个镜像只有960b,可以拿这个练手

    dao pull hello-world
    

     4.2 将hello-world打标签成私服镜像

    docker tag hello-world 192.168.99.100:5000/hello-world
    

    上面的ip要换真实的虚拟机ip,执行完以后,本机镜像文件应该能看到这个images,见下图:

    注:原始镜像hello-world与打tag后的镜像具有相同的IMAGE ID,说明这二个镜像就是同一个,只是tag不同而已。

    4.3 上传到私有仓库

    docker push 192.168.99.100:5000/hello-world
    

    顺利的话,应该很快就能上传完:

    ➜  ~  docker push 192.168.99.100:5000/hello-world
    The push refers to a repository [192.168.99.100:5000/hello-world] (len: 1)
    Sending image list
    Pushing repository 192.168.99.100:5000/hello-world (1 tags)
    3f12c794407e: Image successfully pushed
    975b84d108f1: Image successfully pushed
    Pushing tag for rev [975b84d108f1] on {http://192.168.99.100:5000/v1/repositories/hello-world/tags/latest}
    

    可以直接在浏览器里访问:http://192.168.99.100:5000/v1/search,如果能看到

    {
        "num_results": ​1,
        "query": "",
        "results": 
    [
            {
                "description": "",
                "name": "library/hello-world"
            }
        ]
    }
    

    说明上传成功

    4.4 从私有仓库下载

    因为本机已经有hello-world的镜像了,为了方便验证,先把它删除:

    docker rmi -f hello-world 192.168.99.100:5000/hello-world
    #或
    #docker rmi -f 975b84d108f1 #即:hello-world的IMAGE ID
    

    然后下载:

    docker pull 192.168.99.100:5000/hello-world
    

    内网环境,应该很快就能下载完成:

    ➜  ~  docker pull 192.168.99.100:5000/hello-world
    Using default tag: latest
    Pulling repository 192.168.99.100:5000/hello-world
    975b84d108f1: Download complete
    3f12c794407e: Download complete
    Status: Downloaded newer image for 192.168.99.100:5000/hello-world:latest
    192.168.99.100:5000/hello-world: this image was pulled from a legacy registry.  
    Important: This registry version will not be supported in future versions of docker.

    注:如果私有仓库要放置在公网上,建议还是按官方推荐的做法,设置SSL证书,强制走https协议,否则将有安全风险。

    参考文章:
    1. Docker私有Registry在CentOS6.X下安装指南 
    2. 搭建私有 Docker 仓库服务器
    3. Use private docker registry in OS-X
    4. Deploying a registry server
    5. allow insecure registry in host provisioned with docker-machine
    6. Adding trusted root certificates to the server  
    7. How To Set Up a Private Docker Registry on Ubuntu 14.04

  • 相关阅读:
    C3P0的详细配置说明
    关于commons-fileupload组件上传文件中文名乱码问题
    手写JDBC
    使用try-with-resource遇到的问题
    Java基础学习总结——Java对象的序列化和反序列化
    IDEA查看第三方jar包的源代码时出现Decompiled.class file, bytecode version:52.0 (Java 8)的解决方案
    软件工程课程周进度报告 第六周
    地铁合作的第二周
    第六周进度总结
    地铁合作的第一周
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/docker-private-registry-in-mac-os-x.html
Copyright © 2011-2022 走看看