Install docker on centos7

Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

$ sudo yum remove docker \
                  docker-common \
                  docker-selinux \
                  docker-engine
$ sudo yum-config-manager \
    --add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum install docker-ce
sudo systemctl start docker

sudo docker run hello-world
这一步极有可能出错,为什么呢?因为大中国的“长城”啊,怎么解决?

1:使用代理访问

https://docs.docker.com/engine/admin/systemd/#start-automatically-at-system-boot

Create a systemd drop-in directory for the docker service:

  1. $ sudo mkdir -p /etc/systemd/system/docker.service.d
    
  2. Create a file called /etc/systemd/system/docker.service.d/http-proxy.conf that adds the HTTP_PROXY environment variable:
    [Service]
    Environment="HTTP_PROXY=http://proxy.example.com:80/"
    

    Or, if you are behind an HTTPS proxy server, create a file called /etc/systemd/system/docker.service.d/https-proxy.conf that adds the HTTPS_PROXY environment variable:

    [Service]
    Environment="HTTPS_PROXY=https://proxy.example.com:443/"
    
  3. If you have internal Docker registries that you need to contact without proxying you can specify them via the NO_PROXY environment variable:
    Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"
    

    Or, if you are behind an HTTPS proxy server:

    Environment="HTTPS_PROXY=https://proxy.example.com:443/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"
    
  4. Flush changes:
    $ sudo systemctl daemon-reload
    
  5. Restart Docker:
    $ sudo systemctl restart docker
    
  6. Verify that the configuration has been loaded:
    $ systemctl show --property=Environment docker
    Environment=HTTP_PROXY=http://proxy.example.com:80/
    

    Or, if you are behind an HTTPS proxy server:

    $ systemctl show --property=Environment docker
    Environment=HTTPS_PROXY=https://proxy.example.com:443/
    

2:使用国内docker镜像

https://docs.docker.com/registry/recipes/mirror/#configure-the-docker-daemon

Use case: the China registry mirror

The URL of the registry mirror for China is registry.docker-cn.com. You can pull images from this mirror just like you do for other registries by specifying the full path, including the registry, in your docker pull command, for example:

$ docker pull registry.docker-cn.com/library/ubuntu

You can add "https://registry.docker-cn.com" to the registry-mirrors array in /etc/docker/daemon.json to pull from the China registry mirror by default.

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

Save the file and reload Docker for the change to take effect.

3:有本事自己搞一个镜像本地服务

https://docs.docker.com/registry/deploying/