卸载
执行如下命令,卸载当前系统的 docker
sudo yum remove docker docker-client docker-client-latest \
docker-common docker-latest docker-latest-logrotate \
docker-logrotate docker-engine
更新 yum
# 升级所有的包,同时也升级软件和系统内核
sudo yum -y update
安装 Docker
安装需要的软件包和设置 yum 源
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 设置yum源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum 查看可用版本
sudo yum list docker-ce --showduplicates | sort -r
yum 安装 Docker
这里需要选择docker-ce
相关版本的docker
安装
sudo yum -y install docker-ce-18.06.3.ce
检查安装版本
执行如下命令:
sudo docker version
结果如下
Client:
Version: 18.06.3-ce
API version: 1.38
Go version: go1.10.3
Git commit: d7080c1
Built: Wed Feb 20 02:26:51 2019
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.06.3-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: d7080c1
Built: Wed Feb 20 02:28:17 2019
OS/Arch: linux/amd64
Experimental: false
设置开机自启动并启动 Docker
sudo systemctl enable docker && systemctl start docker
设置镜像源
如果嫌原镜像源速度太慢,可以换成国内各大厂或机构的镜像源。
# 1.创建Docker配置文件夹
sudo mkdir -p /etc/docker
# 2.创建配置:daemon.json
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://6m7no14o.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
EOF
# 3.重启Docker
sudo systemctl daemon-reload && systemctl restart docker
安装 docker-compose
版本发布地址 https://github.com/docker/compose/releases 官方安装教程 https://docs.docker.com/compose/install/
下载二进制文件安装
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 或者
wget https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
授权
sudo chmod +x /usr/local/bin/docker-compose
检查安装版本
docker-compose --version