利用docker-container-搭建docker-registry

53次阅读

共计 1742 个字符,预计需要花费 5 分钟才能阅读完成。

服务端

  1. 启动命令

    • docker run -d -p 5000:5000 –restart always –name registry registry:2
  2. ip 地址及验证 api

客户端


  1. build

    root@swoole_dev:/home/tb/my_docker_helloworld# docker build -t 192.168.1.8:5000/hello_docker:latest .
    Sending build context to Docker daemon  916.5kB
    Step 1/3 : FROM scratch
     ---> 
    Step 2/3 : ADD hello /
     ---> Using cache
     ---> 11b009df24b2
    Step 3/3 : CMD ["/hello"]
     ---> Using cache
     ---> 6c539eb137dd
    Successfully built 6c539eb137dd
    Successfully tagged 192.168.1.8:5000/hello_docker:latest
    
    ## 验证 image
    root@swoole_dev:/home/tb/my_docker_helloworld# docker images |grep 192
    192.168.1.8:5000/hello_docker   latest              6c539eb137dd        21 hours ago        913kB
    root@swoole_dev:/home/tb/my_docker_helloworld# 
    
  2. 验证服务端

    root@swoole_dev:/home/tb/my_docker_helloworld# telnet 192.168.1.8 5000
    Trying 192.168.1.8...
    Connected to 192.168.1.8.
    Escape character is '^]'.
    
  3. 尝试 push

    root@swoole_dev:/home/tb/my_docker_helloworld# docker push 192.168.1.8:5000/hello_docker:latest
    The push refers to repository [192.168.1.8:5000/hello_docker]
    Get https://192.168.1.8:5000/v2/: http: server gave HTTP response to HTTPS client
    root@swoole_dev:/home/tb/my_docker_helloworld# 
    ## 应该是安全策略问题,http vs https
  4. 解决办法

    vim /etc/docker/deamon.json
    ## 增加第二行
    {"registry-mirrors": ["http://d1d9aef0.m.daocloud.io"],
       "insecure-registries":["192.168.1.8:5000"]  
    }
    
    ## 验证结果 1
    root@swoole_dev:/home/tb/my_docker_helloworld# vim /etc/docker/daemon.json
    root@swoole_dev:/home/tb/my_docker_helloworld# service docker restart
    root@swoole_dev:/home/tb/my_docker_helloworld# docker push 192.168.1.8:5000/hello_docker:latest
    The push refers to repository [192.168.1.8:5000/hello_docker]
    096f9105d9f4: Pushed 
    latest: digest: sha256:dc9c69395640d5fd7cb9e4f8bd2bdbf788b206a59e942a2a40577d9b1c089934 size: 527
    root@swoole_dev:/home/tb/my_docker_helloworld# 
  5. 客户端通过 registry api 查看

  6. 如果未成功,尝试如下操作

    vim  /lib/systemd/system/docker.service
    #增加一行
    EnvironmentFile=-/etc/docker/daemon.json
    

more

正文完
 0