Centos:

1.Install using the repository
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

2.INSTALL DOCKER CE
$ sudo yum install docker-ce docker-ce-cli containerd.io

 ($ yum list docker-ce --showduplicates | sort -r 

 $ yum install docker-ce-18.03.0.ce

 $ chkconfig docker on)                         // install a certain version

$ sudo systemctl start docker (service docker start)

Install Docker Engine - Community from binaries

1.Download the static binary archive. Go to https://download.docker.com/linux/static/stable/ (or change stable to nightly or test), choose your hardware platform, and download the .tgz file relating to the version of Docker Engine - Community you want to install.

2.Extract the archive using the tar utility. The dockerd and docker binaries are extracted.

 $ tar xzvf /path/to/<FILE>.tar.gz

3.Optional: Move the binaries to a directory on your executable path, such as /usr/bin/. If you skip this step, you must provide the path to the executable when you invoke docker or dockerd commands. 

 $ sudo cp docker/* /usr/bin/

4.Start the Docker daemon:

 $ sudo dockerd &

5.If you need to start the daemon with additional options, modify the above command accordingly or create and edit the file /etc/docker/daemon.json to add the custom configuration options.

Ubuntu:

  1. Update the apt package index.

    $ sudo apt-get update
    
  2. Install the latest version of Docker Engine - Community and containerd, or go to the next step to install a specific version:

    $ sudo apt-get install docker-ce docker-ce-cli containerd.io
    

    Got multiple Docker repositories?

    If you have multiple Docker repositories enabled, installing or updating without specifying a version in the apt-get install or apt-get update command always installs the highest possible version, which may not be appropriate for your stability needs.

  3. To install a specific version of Docker Engine - Community, list the available versions in the repo, then select and install:

    a. List the versions available in your repo:

    $ apt-cache madison docker-ce
    
      docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
      docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
      docker-ce | 18.06.1~ce~3-0~ubuntu       | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
      docker-ce | 18.06.0~ce~3-0~ubuntu       | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
      ...
    

    b. Install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ubuntu-xenial.

    $ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
    
  4. Verify that Docker Engine - Community is installed correctly by running the hello-world image.

    $ sudo docker run hello-world

SET PROXY
$ sudo mkdir -p /etc/systemd/system/docker.service.d
$ cd /etc/systemd/system/docker.service.d
$ touch http-proxy.conf
$ vi http-proxy.conf                            // add the HTTP_PROXY environment variable
[Service]
Environment = "HTTP_PROXY=http://xxxxxx.com:xx/"
Environment = "HTTPS_PROXY=http://xxxxxx.com:xx/"
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
$ systemctl show --property=Environment docker

PULL DOCKER IMAGE

$ sudo docker run hello-world        // check images if can be pulled

$ sudo docker pull centos:7.6.1810 (or centos:latest or ubuntu:18.04)
$ sudo docker images                  // check if it is successful

$ docker run -itd --privileged ubuntu:18.04 bash 

$ docker container ls

$ docker exec -it $container_id bash