1.卸载旧版本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-ce
2.安装最新版本Docker
1、首先需要大家虚拟机联网,安装yum工具
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2 --skip-broken
2、然后更新本地镜像源:
# 设置docker镜像源
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
yum makecache fast
3、然后输入命令:
yum install -y docker-ce
3.启动docker
1、关闭防火墙(Docker应用需要用到各种端口,逐一去修改防火墙设置。)
# 关闭
systemctl stop firewalld
# 禁止开机启动防火墙
systemctl disable firewalld
# 查看防火墙的状态
systemctl status firewalld
2、通过命令启动docker:
systemctl start docker # 启动docker服务
systemctl stop docker # 停止docker服务
systemctl restart docker # 重启docker服务
systemctl status docker # 查看docker状态
3、查看docker版本:
docker -v
4.配置镜像加速
目的:docker官方镜像仓库网速较差,我们需要设置国内镜像服务:
参考阿里云的镜像加速文档
登入阿里云(自行注册)
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
5.CentOS7安装DockerCompose
1.下载
# 安装
curl -L https://github.com/docker/compose/releases/download/1.23.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
2.修改文件权限
# 修改权限
chmod +x /usr/local/bin/docker-compose
3.Base自动补全命令:
# 补全命令
curl -L https://raw.githubusercontent.com/docker/compose/1.29.1/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose
如果这里出现错误,需要修改自己的hosts文件:
echo "199.232.68.133 raw.githubusercontent.com" >> /etc/hosts
4 permission denied
**永久关闭:**
vim /etc/sysconfig/selinux
SELINUX=enforcing 改为 SELINUX=disable
重启虚拟机