How to change the default docker registry from doc

2019-01-21 00:23发布

By default, if I issue command:

sudo docker pull ruby:2.2.1

it will pull from the docker.io offical site by default.

Pulling repository docker.io/library/ruby

How do I change it to my private registry. That means if I issue

sudo docker pull ruby:2.2.1

it will pull from my own private registry, the output is something like:

Pulling repository my_private.registry:port/library/ruby

6条回答
贼婆χ
2楼-- · 2019-01-21 00:50

UPDATE: Following your comment, it is not currently possible to change the default registry, see this issue for more info.

You should be able to do this, substituting the host and port to your own:

docker pull localhost:5000/registry-demo

If the server is remote/has auth you may need to log into the server with:

docker login https://<YOUR-DOMAIN>:8080

Then running:

docker pull <YOUR-DOMAIN>:8080/test-image
查看更多
地球回转人心会变
3楼-- · 2019-01-21 00:56

It seems it won't be supported due to the fragmentation it would create within the community (i.e. two users would get different images pulling ubuntu:latest). You simply have to add the host in front of the image name. See this github issue to join the discussion.

(Note, this is not intended as an opinionated comment, just a very short summary of the discussion that can be followed in the mentioned github issue.)

查看更多
甜甜的少女心
4楼-- · 2019-01-21 00:59

if you are using the fedora distro, you can change the file

/etc/containers/registries.conf

Adding domain docker.io

查看更多
劳资没心,怎么记你
5楼-- · 2019-01-21 01:06

It turns out this is actually possible, but not using the genuine Docker CE or EE version.

You can either use Red Hat's fork of docker with the '--add-registry' flag or you can build docker from source yourself with registry/config.go modified to use your own hard-coded default registry namespace/index.

查看更多
仙女界的扛把子
6楼-- · 2019-01-21 01:06

Earlier this could be achieved using DOCKER_OPTS in the /etc/default/docker config file which worked on Ubuntu 14:04 and had some issues on Ubuntu 15:04. Not sure if this has been fixed.

The below line needs to go into the file /etc/default/docker on the host which runs the docker daemon. The change points to the private registry is installed in your local network. Note: you would require to restart the docker service followed with this change.

DOCKER_OPTS="--insecure-registry <priv registry hostname/ip>:<port>"
查看更多
趁早两清
7楼-- · 2019-01-21 01:06

Haven't tried, but maybe hijacking the DNS resolution process by adding a line in /etc/hosts for hub.docker.com or something similar (docker.io?) could work?

查看更多
登录 后发表回答