To use Docker, you must download Docker official images, such as MySQL and WordPress. The download of an official image may take a long time, or even fail as a result of network fluctuations. Container Registry provides an image accelerator to speed up the download of Docker official images.

Use the image accelerator

The accelerator configuration varies depending on the operating system. This topic describes the accelerator configurations in major operating systems.

To obtain your accelerator URL, log on to the Container Registry console and choose Image Accelerator in the left-side navigation pane.

Example: Public Mirror: [System-assigned Prefix].mirror.aliyuncs.com    

If your Docker version is up-to-date

If your Docker version is 1.10 or later, we recommend that you use daemon config to configure the accelerator. You can directly modify the configuration file /etc/docker/daemon.json. If the file does not exist, create it.

{    "registry-mirrors": ["<your accelerate address>"]
}

After you saved the changes, restart Docker Daemon.

If your Docker version is outdated

Modify the configuration file, which differs depending on the operating system.

  • Ubuntu 12.04 - 14.04

    In Ubuntu 12.04 to 14.04, the configuration file can be found in directory /etc/default/docker. Add the accelerator configuration to this file and restart Docker.

    echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=<your accelerate address>\"" | sudo tee -a /etc/default/docker
    sudo service docker restart            
  • Ubuntu 15.04 - 15.10

    In Ubuntu 15.04 to 15.10, the configuration file is stored in directory /etc/systemd/system/docker.service.d/. You can create a *.conf file under this directory and use it as the configuration file. Add the accelerator configuration to this file and restart Docker.

    sudo mkdir -p /etc/systemd/system/docker.service.d
    sudo tee /etc/systemd/system/docker.service.d/mirror.conf <<-'EOF'
    [Service]
    ExecStart=
    ExecStart=/usr/bin/docker daemon -H fd:// --registry-mirror=<your accelerate address>
    EOF sudo systemctl daemon-reload
    sudo systemctl restart docker            
  • CentOS 7

    In CentOS, you need to copy the default configuration file in directory /lib/systemd/system/docker.service and paste it into directory /etc/systemd/system/docker.service. Add the accelerator URL to the start command of the configuration file, and then restart Docker.

    sudo cp -n /lib/systemd/system/docker.service /etc/systemd/system/docker.service
    sudo sed -i "s|ExecStart=/usr/bin/docker daemon|ExecStart=/usr/bin/docker daemon --registry-mirror=<your accelerate address>|g" /etc/systemd/system/docker.service
    sudo sed -i "s|ExecStart=/usr/bin/dockerd|ExecStart=/usr/bin/dockerd --registry-mirror=<your accelerate address>|g" /etc/systemd/system/docker.service
    sudo systemctl daemon-reload
    sudo service docker restart            
  • Redhat 7

    In Redhat 7, the configuration file can be found in directory /etc/sysconfig/docker. In the OPTIONS section, add the accelerator configuration as follows: --registry-mirror=<your accelerate address>. Run the sudo service docker restart command to restart Docker Daemon.

  • Redhat 6/CentOS 6

    Docker cannot be installed in these two operating systems. You need to upgrade the OS kernel first.

    To configure the accelerator, modify the /etc/sysconfig/docker configuration file. In the other_args section, add the accelerator configuration as follows: --registry-mirror=<your accelerate address>. Run the sudo service docker restart command to restart Docker Daemon.

  • Docker Toolbox

    If you use Docker Toolbox in Windows or Mac, we recommend that you add the accelerator configuration when you create a Linux VM.

    docker-machine create --engine-registry-mirror=<your accelerate address> -d virtualbox default
    docker-machine env default
    eval "$(docker-machine env default)"
    docker info            

    If you have already created a VM by using docker-machine, you need to log on to the VM to change the configuration.

    1. Run the docker-machine ssh <machine-name> command to log on to the VM.
    2. Modify the file in directory /var/lib/boot2docker/profile. In the EXTRA_ARGS section, add the accelerator configuration as follows: --registry-mirror=<your accelerate address>.
    3. Run the sudo /etc/init.d/docker restart command to restart Docker.

Note

Replace <your accelerate address> with the actual accelerator URL, which can be found in the Container Registry console.