Docker private registry with mirror

后端 未结 3 2061
不思量自难忘°
不思量自难忘° 2020-12-13 10:49

I created two Docker containers. The first one provides a private Docker registry and the second one is a mirror of the official Docker registry:

docker run          


        
3条回答
  •  温柔的废话
    2020-12-13 11:23

    You cannot just force all docker push commands to push to your private registry. One reason is that you can have any number of those registers. You have to first tell docker where to push by tagging the image (see lower).

    Here is how you can setup docker hosts to work with a running private registry and local mirror.

    Client set-up

    Lets assume that you are running both mirror and private registry on (resolvable) host called dockerstore. Mirror on port 5555, registry on 5000.

    Then on client machine(s) you should pass extra options to docker daemon startup. In your case:

    1. Add --registry-mirror=http://dockerstore:5555 to tell daemon to prefer using local mirror rather then dockerhub. source
    2. Add --insecure-registry dockerstore:5000 to access the private registry without further configuration. See this answer
    3. Restart docker daemon

    Using the mirror

    When you pull any image the first source will be the local mirror. You can confirm by running a docker pull, e.g.

    docker pull debian
    

    In the output there will be message that image is being pulled from your mirror - dockerstore:5000

    Using local registry

    In order to push to private registry first you have to tag the image to be pushed with full name of the registry. Make sure that you have a dot or colon in the first part of the tag, to tell docker that image should be pushed to private registry.

    Docker looks for either a “.” (domain separator) or “:” (port separator) to learn that the first part of the repository name is a location and not a user name.

    Example:

    Tag 30d39e59ffe2 image as dockerstore:5000/myapp:stable

    docker tag 30d39e59ffe2 dockerstore:5000/myapp:stable
    

    Push it to private registry

    docker push dockerstore:5000/myapp:stable
    

    Then you can pull as well

    docker pull dockerstore:5000/myapp:stable
    

提交回复
热议问题