docker私有仓库搭建过程报错

docker私有仓库搭建报错:

  • http与https

    [root@swarm1 harbor]# docker ps -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
    7059a75f61d0        f32a97de94e1        "/entrypoint.sh /etc…"   5 minutes ago       Up 5 minutes        0.0.0.0:5000->5000/tcp   registry
    [root@swarm1 harbor]# docker images
    172.17.0.2:5000/game2048   latest              19299002fdbe        2 years ago         55.5MB
    [root@swarm1 harbor]# docker push 172.17.0.2:5000/game2048
    The push refers to repository [172.17.0.2:5000/game2048]
    Get https://172.17.0.2:5000/v2/: http: server gave HTTP response to HTTPS client           # 报错
    

    原因:Docker从1.3.X之后,与docker registry交互默认使用的是https,然而此处搭建的私有仓库只提供http服务,所以当与
    私有仓库交互时就会报上面的错误。为了解决这个问题需要在启动docker server时增加启动参数为默认使用http访问。
    修改docker启动配置文件:

    [root@swarm1 harbor]# vim /usr/lib/systemd/system/docker.service	  
     12 ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --insecure-registry 172.17.0.2:5000
    

    重读重启docker:

    [root@swarm1 harbor]# systemctl daemon-reload 
    [root@swarm1 harbor]# systemctl restart docker
    

    重新上传该镜像:

    [root@swarm1 harbor]# docker push 172.17.0.2:5000/game2048
    The push refers to repository [172.17.0.2:5000/game2048]
    88fca8ae768a: Pushed 
    6d7504772167: Pushed 
    192e9fad2abc: Pushed 
    36e9226e74f8: Pushed 
    011b303988d2: Pushed 
    latest: digest: sha256:8a34fb9cb168c420604b6e5d32ca6d412cb0d533a826b313b190535c03fe9390 size: 1364
    

    /mnt/registry私有库目录中会存在game2048镜像:

    [root@swarm1 ~]# cd /mnt/registry/docker/registry/v2/repositories/
    [root@swarm1 repositories]# ls
    game2048
    

    测试:

    [root@swarm1 repositories]# docker rmi 172.17.0.2:5000/game2048:latest 
    Untagged: 172.17.0.2:5000/game2048:latest
    Untagged: 172.17.0.2:5000/game2048@sha256:8a34fb9cb168c420604b6e5d32ca6d412cb0d533a826b313b190535c03fe9390
    [root@swarm1 repositories]# docker images
     REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    registry            2                   f32a97de94e1        10 days ago         25.8MB
    swarm               latest              ff454b4a0e84        9 months ago        12.7MB
    game2048            latest              19299002fdbe        2 years ago         55.5MB
    nginx               latest              af4b3d7d5401        3 years ago         191MB
    [root@swarm1 repositories]# docker pull 172.17.0.2:5000/game2048
    Using default tag: latest
    latest: Pulling from game2048
    Digest: sha256:8a34fb9cb168c420604b6e5d32ca6d412cb0d533a826b313b190535c03fe9390
    Status: Downloaded newer image for 172.17.0.2:5000/game2048:latest
    [root@swarm1 repositories]# docker images
    REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
    registry                   2                   f32a97de94e1        10 days ago         25.8MB
    swarm                      latest              ff454b4a0e84        9 months ago        12.7MB
    172.17.0.2:5000/game2048   latest              19299002fdbe        2 years ago         55.5MB
    game2048                   latest              19299002fdbe        2 years ago         55.5MB
     nginx                      latest              af4b3d7d5401        3 years ago         191MB
    

你可能感兴趣的:(学习问题扩展)