一、安装条件

  • 1.1 操作系统要求 安装Docker Engine,需要Centos7以上版本。该centos-extras库必须启用,默认情况下,此存储库是启用的,如已禁用,则需要启用它。
  • 1.2 卸载旧版本
	$ yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

二、安装Docker Engine

2.1 使用存储库安装

首次安装Docker Engine,需要设置Docker存储库,之后可以从存储库安装和更新Docker。

2.1.1 设置存储库

安装yum-utils软件包并设置存储库
	$ sudo yum install -y yum-utils

	$ sudo yum-config-manager \
			--add-repo \
			https://download.docker.com/linux/centos/docker-ce.repo

2.1.2 安装最新版本的Docker Engine

	$ yum install docker-ce docker-ce-cli containerd.io

2.1.3 安装特定版本的Docker Engine

	$ yum list docker-ce --showduplicates | sort -r
		docker-ce.x86_64            3:19.03.9-3.el7                    docker-ce-stable 
		docker-ce.x86_64            3:19.03.8-3.el7                    docker-ce-stable 
		docker-ce.x86_64            3:19.03.7-3.el7                    docker-ce-stable 
		docker-ce.x86_64            3:19.03.6-3.el7                    docker-ce-stable 
		docker-ce.x86_64            3:19.03.5-3.el7                    docker-ce-stable 
		docker-ce.x86_64            3:19.03.4-3.el7                    docker-ce-stable 
		docker-ce.x86_64            3:19.03.3-3.el7                    docker-ce-stable 
		docker-ce.x86_64            3:19.03.2-3.el7                    docker-ce-stable 
		docker-ce.x86_64            3:19.03.1-3.el7                    docker-ce-stable 
		docker-ce.x86_64            3:19.03.12-3.el7                   docker-ce-stable 
		docker-ce.x86_64            3:19.03.12-3.el7                   @docker-ce-stable

2.1.4 启动Docker

$ systemctl start docker

  • 通过运行hello-world镜像来验证是否正确安装了Docker Engine $ docker run hello-world
    运行成功:
    	Unable to find image 'hello-world:latest' locally
    	latest: Pulling from library/hello-world
    	0e03bdcc26d7: Pull complete 
    	Digest: sha256:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202
    	Status: Downloaded newer image for hello-world:latest
    
    	Hello from Docker!
    	This message shows that your installation appears to be working correctly.
    
    	To generate this message, Docker took the following steps:
    	 1. The Docker client contacted the Docker daemon.
    	 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    			(amd64)
    	 3. The Docker daemon created a new container from that image which runs the
    			executable that produces the output you are currently reading.
    	 4. The Docker daemon streamed that output to the Docker client, which sent it
    			to your terminal.
    
    	To try something more ambitious, you can run an Ubuntu container with:
    	 $ docker run -it ubuntu bash
    
    	Share images, automate workflows, and more with a free Docker ID:
    	 https://hub.docker.com/
    
    	For more examples and ideas, visit:
    	 https://docs.docker.com/get-started/
    
运行失败:
	Unable to find image 'hello-world:latest' locally
	latest: Pulling from library/hello-world
	0e03bdcc26d7: Pulling fs layer 
	docker: error pulling image configuration: Get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/bf/bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b/data?verify=1596011879-aGOPb8c3qXZ1NaIw850GXq569U0%3D: dial tcp 104.18.123.25:443: i/o timeout.
	See 'docker run --help'.
	注意:出现以上错误信息,在/etc/resolv.conf文件中新增参数nameserver 8.8.8.8,修改完成后需重启Docker Engine 如下:
	$ vi /etc/resolv.conf
	# Generated by NetworkManager
	search localdomain
	nameserver 192.168.189.2
	nameserver 8.8.8.8

#### 2.1.5 重启Docker Engine
`	$ service docker restart`