docker 安装方式(centos7)
文章目录
设置yum源(阿里云)
1.备份你的原镜像文件,以免出错后可以恢复。
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup2.下载新的CentOS-Base.repo 到/etc/yum.repos.d/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo3.生成缓存
yum makecache设置存储库
1.存储驱动若使用 devicemapper ,需依赖于device-mapper-persistent-data 和 lvm2,(若不是请忽略这一步)
yum install -y yum-utils device-mapper-persistent-data lvm2
2.设置稳定的存储库(阿里云源),官方库:https://download.docker.com/linux/centos/docker-ce.repo
# yum-config-manager 依赖于 yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装Docker CE
1.安装
# 查看可安装版本
yum list docker-ce --showduplicates | sort -r
# 安装指定版本
yum -y install docker-ce-<VERSION_STRING>
# 安装最新版
yum -y install docker-ce
若出现以下报错,请安装新版containerd.io
Error:
Problem: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed# 安装新版containerd.io
# https://download.docker.com/linux/centos/7/x86_64/stable/Packages/ontainerd.io-1.2.13-3.2.el7.x86_64.rpm
yum -y install http://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm
# 安装docker-ce
yum -y install docker-ce2.管理docker
# 启动
systemctl start docker
# 关闭
systemctl stop docker
# 开机自启
systemctl enable docker3.卸载
yum remove docker-ce docker-ce-cli containerd.io
# 指定版本
yum remove docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
# 卸载老版本
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine删除镜像和容器文件/var/lib/docker/(默认存放地址)
docker-compose
- 从github上下载
# 要安装不同版本的Compose,请使用您想要使用的Compose版本替代1.25.4。
curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 增加执行权限
chmod +x /usr/local/bin/docker-compose- 从daocloud上下载(速度快)
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# 增加执行权限
chmod +x /usr/local/bin/docker-composedocker & firewalld
如果先运行dockerd再运行firewalld, 会导致 Docker 无法正常工作,容器内部无法正常访问网络
解决方案:
第一种:修改docker网络模式为host
- docker run
在运行容器时添加参数 --network=host
docker run --network=host ...- docker compose
network_mode: "host"第二种:将firewalld换成iptables(推荐)
# 查看firewalld是否启用
$ systemctl status firewalld
# 停止firewalld
$ systemctl stop firewalld
# 禁用firewalld(否则重启系统后会再次启动)
$ systemctl disable firewalld
# 查看是否安装iptables
$ dnf list installed | grep iptables-services
# 如果没安装则安装下
$ dnf -y install iptables-services
# 重启iptables
$ systemctl restart iptables
# 设置开机自启
$ systemctl enable iptables
# 重启docker
systemctl restart docker第三种:关闭防火墙
# 查看firewalld是否启用
$ systemctl status firewalld
# 停止firewalld
$ systemctl stop firewalld
# 禁用firewalld(否则重启系统后会再次启动)
$ systemctl disable firewalld
# 重启docker
$ systemctl restart docker
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论