Custom Docker

1. Use Docker custom Mirror

Centos 6

1
$ vim /etc/sysconfig/docker

Add a row:

1
other_args="--registry-mirror=https://registry.docker-cn.com"

Centos 7

1
$ vim /etc/docker/daemon.json

After adding:

1
2
3
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}

or

1
2
3
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}

Restart the Docker service:

1
2
3
systemctl restart docker
# or
service docker restart

2. Let docker use the proxy

Centos 7

First, create a systemd drop-in directory for the docker service:

1
mkdir /etc/systemd/system/docker.service.d

Now create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:

1
2
3
[Service]
Environment="HTTP_PROXY=http://your_proxy_ip:port"
Environment="NO_PROXY=localhost,127.0.0.0"

Flush changes:

1
$ sudo systemctl daemon-reload

Verify that the configuration has been loaded:

1
2
$ sudo systemctl show --property Environment docker
Environment=HTTP_PROXY=http://your_proxy_ip:port

Restart Docker:

1
$ sudo systemctl restart docker

Centos 6

1
2
3
4
5
6
7
vim /etc/sysconfig/docker
# insert
export http_proxy=http://your_proxy_ip:port
export https_proxy=http://your_proxy_ip:port
export NO_PROXY=localhost,127.0.0.0
# restart
service docker restart

3. Create a local docker mirror repository

Install and run docker-registry

1
$ docker run -d -p 5000:5000 --name registry registry:2

This will use the official registry image to start the private repository. By default, the repository is created in the container’s /var/lib/registry directory. , You can use the -v parameter to store the image in a local path. For example, the following example places the uploaded image in the local /opt/data/registry directory.

1
2
3
4
5
$ docker run -d --name 02-registry --restart always \
-p 5000:5000 \
-v /opt/data/registry:/var/lib/registry \
--name registry \
registry:2
咕咕咕