利用docker container 搭建docker registry

牙小木木

服务端

  1. 启动命令

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

clipboard.png

客户端


  1. build

    [email protected]_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
    [email protected]_dev:/home/tb/my_docker_helloworld# docker images |grep 192
    192.168.1.8:5000/hello_docker   latest              6c539eb137dd        21 hours ago        913kB
    [email protected]_dev:/home/tb/my_docker_helloworld# 
    
  2. 验证服务端

    [email protected]_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

    [email protected]_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
    [email protected]_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
    [email protected]_dev:/home/tb/my_docker_helloworld# vim /etc/docker/daemon.json
    [email protected]_dev:/home/tb/my_docker_helloworld# service docker restart
    [email protected]_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
    [email protected]_dev:/home/tb/my_docker_helloworld# 
  5. 客户端通过registry api 查看

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

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

more

阅读 1.4k

差的很多
每一个真实现在都是你曾经幻想未来

iamtb.cn

1.5k 声望
79 粉丝
0 条评论

iamtb.cn

1.5k 声望
79 粉丝
文章目录
宣传栏