CentOS仅在发行版本的内核支持Docker。要求系统为64位、系统内核版本为3.10以上,这里的示例是CentOS7。
Docker分为Docker CE和Docker EE两种版本。
Docker CE即社区免费版,Docker EE即企业版,强调安全,但需付费使用。
依照Docker的官方文档安装:文档地址:https://docs.docker.com/install/linux/docker-ce/centos/#install-using-the-repository
(下面的步骤都摘取自官网,更多详细介绍请参照官网)
1、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-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2、Install using the repository(配置安装Docker的仓库地址)
Before you install Docker Engine - Community for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
SET UP THE REPOSITORY
-
Install required packages.
yum-utils
provides theyum-config-manager
utility, anddevice-mapper-persistent-data
andlvm2
are required by thedevicemapper
storage driver.$ sudo yum install -y yum-utils \ device-mapper-persistent-data \ lvm2
-
Use the following command to set up the stable repository.
官网原命令(不建议): $ sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo 上面的地址是国外地址,后面执行Docker安装命令时会非常慢。 国内用户可以不执行上面的,而执行下面这条,把地址配置成阿里云的地址 $ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 配置yum的仓库地址后,更新yum缓存 $ sudo yum makecache fast
3、INSTALL DOCKER ENGINE - COMMUNITY(安装Docker社区版--最新版)
-
Install the latest version of Docker Engine - Community and containerd, or go to the next step to install a specific version:
$ sudo yum install docker-ce docker-ce-cli containerd.io
-
Start Docker.(启动Docker)
$ sudo systemctl start docker
-
Verify that Docker Engine - Community is installed correctly by running the
hello-world
image.(运行一个hello-world镜像)$ sudo docker run hello-world
4、配置Docker的国内镜像仓库地址(这里采用的是阿里云的容器镜像仓库地址)
(这一步可在第三步安装好Docker就操作,配置镜像仓库地址)
地址:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
登录进去后就可以看到下图,每个人分配的镜像地址是不一样的
图中框柱的是CentOS7的配置方法:可以直接在Linux上执行这几行命令,即可完成镜像仓库地址的配置。