1.卸载
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
2.安装工具
yum install -y yum-utils
3.设置Yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4.安装docker
yum -y install docker-ce docker-ce-cli containerd.io
注意 安装时 出现 container-selinux >= 2.9 解决办法:
#进入yum 源配置文件夹 cd /etc/yum.repos.d mv CentOS-Base.repo
CentOS-Base.repo_bak在文件顶部添加一个条目/etc/yum.repos.d/docker-ce.repo,内容如下:
[centos-extras]
name=Centos extras - $basearch
baseurl=http://mirror.centos.org/centos/7/extras/x86_64 enabled=1
gpgcheck=0保存退出
#然后安装命令: yum -y install slirp4netns fuse-overlayfs container-selinux
5.启动Docker并设置为开机自启
# 启动docker
systemctl start docker
# 开机自启
systemctl enable docker
6.配置镜像
1.在 /etc/docker/daemon.json 文件中添加以下参数(没有该文件则新建):
{
"registry-mirrors": [
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
]
}
2.重启
sudo systemctl daemon-reload
sudo systemctl restart docker
7.安装docker-compose
- 下载安装
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
没有安装 curl 的先安装,安装包的安装方式如下
从官网下载安装包:https://github.com/docker/compose/releases/tag/1.25.0-rc4
,将安装包放置 /usr/local/bin 目录下,并改名为 docker-compose
- 授权
chmod +x /usr/local/bin/docker-compose