zoukankan      html  css  js  c++  java
  • [docker]本地仓库的创建的使用

    如果自己创建的镜像可以供其他同事使用,那就可以大大节约开发时间成本,docker的本地仓库正好可以满足这样的需求

    1、在仓库服务器上创建本地仓库

    baylor@baylor-virtual-machine:~$ docker run -d -p 5000:5000 --name registry registry:2

    2、在需要上传的服务器上先得到个镜像

    baylor@baylor-virtual-machine:~$ docker pull busybox

    3、为准备上传的镜像改个tag

    baylor@baylor-virtual-machine:~$ docker tag busybox 192.168.133.165:5000/busybox

    4、将本地的镜像推送到本地仓库服务器

    baylor@baylor-virtual-machine:~$ docker push 192.168.133.165:5000/busybox

    可能会遇到以下的错误信息:

    FATA[0000] Error response from daemon: v1 ping attempt failed with error: Get https://192.168.133.165:5000/v1/_ping: local error: record overflow. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 192.168.133.165:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/192.168.133.165:5000/ca.crt 

    因为Docker从1.3.X之后默认docker registry使用的是https,所以当用docker pull命令下载远程镜像时,如果远程docker registry是非https的时候就会报上面的错误。

    解决方法为在docker的配置文件里添加--insecure-registry参数

    baylor@baylor-virtual-machine:~$ cat /etc/default/docker 
    # Docker Upstart and SysVinit configuration file
    
    # Customize location of Docker binary (especially for development testing).
    #DOCKER="/usr/local/bin/docker"
    
    # Use DOCKER_OPTS to modify the daemon startup options.
    #DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
    
    # If you need Docker to use an HTTP proxy, it can also be specified here.
    #export http_proxy="http://127.0.0.1:3128/"
    
    # This is also a handy place to tweak where Docker's temporary files go.
    #export TMPDIR="/mnt/bigdrive/docker-tmp"
    DOCKER_OPTS="--insecure-registry 192.168.133.165:5000"     《-------在这里

    5、重启docker后再次推送

    baylor@baylor-virtual-machine:~$ sudo service docker restart

    6、到另外一台机器上去拉镜像(如果也有证书问题,说明也要需要在/etc/default/docker的配置文件里添加registry参数的)

    baylor@baylor-virtual-machine:~$ docker pull 192.168.133.165:5000/busybox

    7、注意:

    因为本地仓库也是一个容器,那么当这个窗口被误删除时,它里面的镜像也会随之删除。所以在创建这个容器的时候最好使用-v参数将数据持久化

    我创建的本地仓库存放其它镜像的地址是/var/lib/registry/docker/registry/v2/repositories/,各位在使用的时候情况可能有所不同

    baylor@baylor-virtual-machine:~$ sudo docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry/docker/registry/v2/repositories/ --name registry
  • 相关阅读:
    LeetCode--Array--Two sum (Easy)
    LeetCode--Unique Email Addresses & Hamming Distance (Easy)
    LeetCode--Squares of a Sorted Array && Robot Return to Origin (Easy)
    LeetCode--Sort Array By Parity && N-Repeated Element in Size 2N Array (Easy)
    LeetCode 11月第1周题目汇总
    LeetCode 十月份题目汇总
    【每天一题】LeetCode 172. 阶乘后的零
    【每天一题】LeetCode 121. 买卖股票的最佳时机
    【每天一题】LeetCode 0107. 自底向上层遍历二叉树
    【每天一题】LeetCode 0067. 二进制求和
  • 原文地址:https://www.cnblogs.com/baylorqu/p/9541375.html
Copyright © 2011-2022 走看看