How to push a docker image to a private repository

后端 未结 9 1146
再見小時候
再見小時候 2020-11-29 14:21

I have a docker image tagged as me/my-image, and I have a private repo on the dockerhub named me-private.
When I push my me/my-image

9条回答
  •  渐次进展
    2020-11-29 14:58

    Ref: dock.docker.com

    This topic provides basic information about deploying and configuring a registry

    Run a local registry

    Before you can deploy a registry, you need to install Docker on the host.

    Use a command like the following to start the registry container:

    start_registry.sh

    #!/bin/bash
    
    docker run -d \
      -p 5000:5000 \
      --restart=always \
      --name registry \
      -v /data/registry:/var/lib/registry \
      registry:2
    

    Copy an image from Docker Hub to your registry

    1. Pull the ubuntu:16.04 image from Docker Hub.

      $ docker pull ubuntu:16.04
      
    2. Tag the image as localhost:5000/my-ubuntu. This creates an additional tag for the existing image. When the first part of the tag is a hostname and port, Docker interprets this as the location of a registry, when pushing.

      $ docker tag ubuntu:16.04 localhost:5000/my-ubuntu
      
    3. Push the image to the local registry running at localhost:5000:

      $ docker push localhost:5000/my-ubuntu
      
    4. Remove the locally-cached images. This does not remove the localhost:5000/my-ubuntu image from your registry.

      $ docker image remove ubuntu:16.04
      $ docker image remove localhost:5000/my-ubuntu
      
    5. Pull the localhost:5000/my-ubuntu image from your local registry.

      $ docker pull localhost:5000/my-ubuntu
      
    Deploy a plain HTTP registry

    According to docs.docker.com, this is very insecure and is not recommended.

    1. Edit the daemon.json file, whose default location is /etc/docker/daemon.json on Linux or C:\ProgramData\docker\config\daemon.json on Windows Server. If you use Docker for Mac or Docker for Windows, click Docker icon -> Preferences -> Daemon, add in the insecure registry.

      If the daemon.json file does not exist, create it. Assuming there are no other settings in the file, it should have the following contents:

      {
        "insecure-registries" : ["myregistrydomain.com:5000"]
      }
      

      With insecure registries enabled, Docker goes through the following steps:

      • First, try using HTTPS.
        • If HTTPS is available but the certificate is invalid, ignore the error about the certificate.
        • If HTTPS is not available, fall back to HTTP.
    2. Restart Docker for the changes to take effect.

提交回复
热议问题