一、安装前准备
1、硬件要求
CentOS 7(64-bit),内核版本不能低于3.10;
CentOS 6.5(64-bit或更新的版本),内核版本为 2.6.32-431 或者更高版本,一般不建议在CentOS 6.x下安装Docker,因为往往CentOS 6.x往往需要先升级内核版本以达到安装条件,但是升级内核可能会导致开不了机之类的问题。
2、卸载旧版本
较旧版本的Docker被称为docker
或docker-engine
。如果已安装这些,请卸载它们以及相关的依赖项。
- $ sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
二、安装Docker
1、使用yum安装
①.安装所需依赖包
- 1 sudo yum install -y yum-utils device-mapper-persistent-data lvm2
鉴于国内网络问题,强烈建议使用国内源!!!
国内源:
- 1 sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
官方源:
- 1 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
如果需要测试版本的 Docker CE 请使用以下命令:
- 1 sudo yum-config-manager --enable docker-ce-test
如果需要每日构建版本的 Docker CE 请使用以下命令:
- 1 sudo yum-config-manager --enable docker-ce-nightly
②.更新yum缓存并安装Docker-ce
- 1 sudo yum makecache fast
- 2 sudo yum -y install docker-ce
③.启动Docker-ce
- 1 sudo systemctl enable docker
- 2 sudo systemctl start docker
④.建立docker用户组
默认情况下,docker
命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root
用户和 docker
组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root
用户。因此,更好地做法是将需要使用 docker
的用户加入 docker
用户组。
建立docker组:
将当前用户添加到docker组中:
- 1 sudo usermod -aG docker $USER
退出当前终端并重新登录,进行如下命令测试,若能正常输出以上信息,则说明安装成功。
- [root@localhost ~]# docker run hello-world
- 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/
⑤.镜像加速
如果在使用过程中发现国内网络拉取 Docker 镜像十分缓慢,比如出现拉取镜像Timeout的问题,可以配置 Docker 国内镜像加速。
例如,对于使用 systemd 的系统,请在 /etc/docker/daemon.json
中写入如下内容(如果文件不存在请新建该文件)
- {
- "registry-mirrors": [
- "https://dockerhub.azk8s.cn",
- "https://reg-mirror.qiniu.com"
- ]
- }
- #注意,一定要保证该文件符合 json 规范,否则 Docker 将不能启动。
重启docker服务:
- 1 sudo systemctl daemon-reload
- 2 sudo systemctl restart docker
查看加速器是否生效:
执行 docker info
,如果从结果中看到了如下内容,说明配置成功。
- Registry Mirrors:
- https://dockerhub.azk8s.cn/
- https://reg-mirror.qiniu.com/
2、使用脚本自动安装
在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,CentOS 系统上可以使用这套脚本安装:
- 1 curl -fsSL get.docker.com -o get-docker.sh
- 2 sudo sh get-docker.sh --mirror Aliyun
执行这个命令后,脚本就会自动的将一切准备工作做好,并且把 Docker CE 的 edge 版本安装在系统中。
3、添加内核参数
如果在 CentOS 使用 Docker CE 看到下面的这些警告信息:
- WARNING: bridge-nf-call-iptables is disabled
- WARNING: bridge-nf-call-ip6tables is disabled
请添加内核配置参数以启用这些功能。
- 1 sudo tee -a /etc/sysctl.conf <<-EOF
- 2 net.bridge.bridge-nf-call-ip6tables = 1
- 3 net.bridge.bridge-nf-call-iptables = 1
- 4 EOF
然后重新加载 sysctl.conf
即可
4、参考文档:
2019-07-07 17:28:49