Centos 7 中Docker 的安装
一、官方安装方式:
docker-ce的release计划跟随moby的release计划,可以使用下面的命令直接安装最新的docker-ce:
# curl -fsSL [https://get.docker.com/](https://get.docker.com/) | sh
Centos
如果是centos,上面的安装命令会在系统上添加yum源:/etc/yum.repos.d/docker-ce.repo
# wget https://download.docker.com/linux/centos/docker-ce.repo
# mv docker-ce.repo /etc/yum.repos.d
# yum install -y docker-ce
或者直接下载rpm安装
# wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm
# yum localinstall docker-ce-17.09.0.ce-1.el7.centos.x86_64.rpm
二、国内源安装方式
使用aliyun docker yum源安装新版docker
删除已安装的Docker
# yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
配置阿里云Docker Yum源
# yum install -y yum-utils device-mapper-persistent-data lvm2 git
# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装指定版本
查看Docker版本:
# yum list docker-ce --showduplicates
安装较旧版本(比如Docker 17.03.2) :
需要指定完整的rpm包的包名,并且加上--setopt=obsoletes=0 参数:
# yum install -y --setopt=obsoletes=0 \
docker-ce-17.03.2.ce-1.el7.centos.x86_64 \
docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch
安装Docker新版本(比如Docker 18.03.0):
加上rpm包名的版本号部分或不加都可以:
# yum install docker-ce-18.03.0.ce -y
或者
# yum install docker-ce -y
启动Docker服务:
#systemctl enable docker
#systemctl start docker
查看docker版本状态:
# docker -v
Docker version 1.13.1, build 8633870/1.13.1
# docker version
Client:
Version: 18.09.0
API version: 1.39
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:48:22 2018
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.0
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 4d60db4
Built: Wed Nov 7 00:19:08 2018
OS/Arch: linux/amd64
Experimental: false
报错1:
docker info的时候报如下错误
bridge-nf-call-iptables is disabled
解决1:
追加如下配置,然后重启系统
# vim /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
问题2:
虚拟机ping百度也能ping通,但是需要等好几秒才出结果,关键是下载镜像一直报错如下
# docker pull daocloud.io/library/nginx
Using default tag: latest
Error response from daemon: Get https://daocloud.io/v2/: dial tcp: lookup daocloud.io on 192.168.1.2:53: read udp 192.168.1.189:41335->192.168.1.2:53: i/o timeout
解决2:
我的虚拟机用的网关和dns都是虚拟机自己的.1或者.2,把DNS改成8.8.8.8问题就解决了,ping百度也秒出结果
# vim /etc/resolv.conf
nameserver 8.8.8.8
报错:yum makecache 报错 是阿里源的问题
vim CentOS-Base.repo
:%s/$releasever/7/g
之后yum makecache 就ok了