转载请注明出处,本文仅用于学习交流,不对之处,恳请指正,部分图片摘取网络,如有侵权请联系
为什么选择OpenEuler
-
之前CentOS忽然停止维护
-
OpenEuler也是Redhat系的衍生版本
-
正巧想要一个虚拟机专门来运行docker
为什么要特意写这篇文章
-
OpenEuler不能直接安装最新的Docker CE版本,OpenEuler默认能够安装的版本为18.09.0
-
我在使用该版本的过程中发现该版本重启之后会自动重置docker的网络配置,以及docker容器之间,即使在同网段仍然无法互通等情况,故弃坑(实在是不想研究)...
配置软件源
OpenEuler配置CentOS软件源
-
新增CentOS软件源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-7-reg.repo
-
修改CentOS-7-reg.repo
sed -i 's/$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
-
查看以下修改效果
cat /etc/yum.repos.d/CentOS-Base.repo
应该所有的$releasever都变成7才对
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-7 - Base - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/os/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os gpgcheck=1 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-7 - Updates - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/updates/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates gpgcheck=1 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-7 - Extras - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/extras/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras gpgcheck=1 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-7 - Plus - repo.huaweicloud.com baseurl=https://repo.huaweicloud.com/centos/7/centosplus/$basearch/ #mirrorlist=https://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=https://repo.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
OpenEuler配置Docker CE软件源
-
添加Docker-CE软件源
wget -O /etc/yum.repos.d/docker-ce.repo https://repo.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo
-
修改docker-ce.repo
sed -i 's/$releasever/7/g' /etc/yum.repos.d/docker-ce.repo
-
查看以下修改效果
cat /etc/yum.repos.d/docker-ce.repo
应该所有的$releasever都变成7才对
[docker-ce-stable] name=Docker CE Stable - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/stable enabled=1 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-stable-debuginfo] name=Docker CE Stable - Debuginfo $basearch baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-stable-source] name=Docker CE Stable - Sources baseurl=https://download.docker.com/linux/centos/7/source/stable enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test] name=Docker CE Test - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/test enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test-debuginfo] name=Docker CE Test - Debuginfo $basearch baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/test enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=https://download.docker.com/linux/centos/7/source/test enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-nightly] name=Docker CE Nightly - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-nightly-debuginfo] name=Docker CE Nightly - Debuginfo $basearch baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/nightly enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-nightly-source] name=Docker CE Nightly - Sources baseurl=https://download.docker.com/linux/centos/7/source/nightly enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg
刷新软件源
yum clean all && yum makecache
允许IPv4转发
Docker运行需要允许网络转发
nano /etc/sysctl.conf
将其中的net.ipv4.ip_forward修改为1
net.ipv4.ip_forward=1
使其生效
sysctl -p
OpenEuler安装Docker CE
-
删除旧版本
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
-
安装
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
-
启动
sudo systemctl start docker
-
开机运行
sudo systemctl enable docker
测试
sudo docker run hello-world
Docker免Root运行
usermod -aG docker ${USER}
移除软件源
保持系统干净,因为非官方指定的软件源,故还是选择避免污染
Docker
mv /etc/yum.repos.d/docker-ce.repo /etc/yum.repos.d/docker-ce.repo.bak
CentOS
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
刷新
yum clean all && yum makecache
文章评论
感谢指导。
内核参数修改后需要 sysctl -p 或者重启生效(虽然我还不知道为什么要开启ipv4转发)
@silence 感谢补充,没注意到这个遗漏。
ip_forward=0会影响容器的外部通信、容器间的通信。一般情况下,docker服务启动会自动修改系统的值,部分情况需要手动修改。