How to push a docker image to a private repository

后端 未结 9 1107
再見小時候
再見小時候 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:45

    There are two options:

    1. Go into the hub, and create the repository first, and mark it as private. Then when you push to that repo, it will be private. This is the most common approach.

    2. log into your docker hub account, and go to your global settings. There is a setting that allows you to set what your default visability is for the repositories that you push. By default it is set to public, but if you change it to private, all of your repositories that you push will be marked as private by default. It is important to note that you will need to have enough private repos available on your account, or else the repo will be locked until you upgrade your plan.

    0 讨论(0)
  • 2020-11-29 14:47

    You need to tag your image correctly first with your registryhost:

    docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
    

    Then docker push using that same tag.

    docker push NAME[:TAG]
    

    Example:

    docker tag 518a41981a6a myRegistry.com/myImage
    docker push myRegistry.com/myImage
    
    0 讨论(0)
  • 2020-11-29 14:55

    Create repository on dockerhub :

    $docker tag IMAGE_ID UsernameOnDockerhub/repoNameOnDockerhub:latest

    $docker push UsernameOnDockerhub/repoNameOnDockerhub:latest

    Note : here "repoNameOnDockerhub" : repository with the name you are mentioning has to be present on dockerhub

    "latest" : is just tag

    0 讨论(0)
  • 2020-11-29 14:55

    Simple working solution:

    Go here https://hub.docker.com/ to create a PRIVATE repository with name for example johnsmith/private-repository this is the NAME/REPOSITORY you will use for your image when building the image.

    • First, docker login

    • Second, I use "docker build -t johnsmith/private-repository:01 ." (where 01 is my version name) to create image, and I use "docker images" to confirm the image created such as in this yellow box below: (sorry I can not paste the table format but the text string only)

    johnsmith/private-repository(REPOSITORY) 01(TAG) c5f4a2861d6e(IMAGE ID) 2 days ago(CREATED) 305MB(SIZE)

    • Third, I use docker push johnsmith/private-repository:01 (Your private repo will be here example https://hub.docker.com/r/johnsmith/private-repository/)

    Done!

    0 讨论(0)
  • 2020-11-29 14:56

    Just three simple steps:

    1. docker login --username username

      • prompts for password if you omit --password which is recommended as it doesn't store it in your command history
    2. docker tag my-image username/my-repo

    3. docker push username/my-repo

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题