上回书说到,已经通过VMware Workstation Pro安装了RedHat虚拟机,现在尝试一下是否可以在虚拟机中安装docker;
一、前置条件
CentOS 7内核版本需>=3.10;
CentOS 6.5或以上内核版本需>=2.6.32;
安装docker前请查看服务器系统版本以及内核版本是否符合要求;
cat /etc/redhat-release && uname -r
二、建立docker用户组
正常情况下,只有 root
用户和 docker
组的用户才可以访问 docker,为了安全,可以将使用docker的用户添加到docker用户组合;
添加docker用户组;
sudo groupadd docker
将当前用户添加到docker用户组中;
sudo usermod -aG docker $USER
二、替换yum源
因为红帽的yum源需要收费,使用yum命令的时候会报:This system is not registered to Red Hat Subscription Management 的错误,解决步骤可以看我的这一篇文章;
https://blog.csdn.net/chililopp/article/details/140105286?spm=1001.2014.3001.5501
三、安装docker依赖包yum-utils
Docker安装需要yum-utils
这个工具,它提供了yum-config-manager的
功能;
sudo yum install -y yum-utils
显示complete即为安装成功;
四、添加Docker的官方仓库到yum源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
但是不知道为什么,当写这一篇文章的时候连接不到官方仓库地址,所以我就自己创建了一个docker-ce.repo文件;
sudo vim /etc/yum.repos.d/docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://download.docker.com/linux/centos/$releasever/$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/$releasever/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/$releasever/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/$releasever/$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/$releasever/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/$releasever/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/$releasever/$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/$releasever/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/$releasever/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://download.docker.com/linux/centos/gpg
然后替换https://download.docker.com为清华大学的开源镜像源地址;
sudo sed -i 's+https://download.docker.com+https://mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
五、然后通过yum安装Docker Engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
显示complete即安装成功
五、安装完成以后启动Docker;
systemctl start docker
六、为了方便,可以将Docker设置为开机自启动;
sudo systemctl enable docker
七、可以查看是否已经成功安装
可以查看一下docker的版本:
docker --version
也可以查看docker的进程:
ps -ef|grep docker
运行一个简单的Docker容器,验证Docker环境:
docker run hello-world
报错了,配置一下国内镜像源试试;
七、Docker镜像加速
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://mirror.gcr.io",
"https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc",
]
}
wq保存一下,重新加载一下配置并重启;
systemctl daemon-reload && sudo systemctl restart docker
但又有新的报错信息,提示
八、重新配置runc
使用docker version 发现没有runc
systemctl status docker
查看docker状态中也提示runc缺失
运行一下runc -version 提示报错,看样子应该是缺失了依赖包;
yum install libseccomp-devel
安装一下,完成;
激动人心的时刻到了,docker运行hello-world,完美成功,搞定!
我是chililopp,正在学习k8s,之后如果有新的总结或者体验也会发出来,如果有说的不对的地方,还请指点,十分感谢阅读!
标签:8.0,centos,com,linux,https,Enterprise,download,docker,Hat From: https://blog.csdn.net/chililopp/article/details/140017653