Centos安装docker-程序员宅基地

技术标签: Docker  centos  docker  

先上菜后详解

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
mkdir -p /opt/docker
#docker 19.xx 之后
sed -i 's/-H/ \-\-data\-root \/opt\/docker &/' /usr/lib/systemd/system/docker.service
#docker 19.xx及之前
sed -i 's/-H/ \-\-graph \/opt\/docker &/' /usr/lib/systemd/system/docker.service
systemctl daemon-reload
systemctl restart docker
systemctl enable docker

#可选 portainer (docker可视化管理平台)
docker pull 6053537/portainer-ce 
docker volume create portainer_data
docker run \
-d \
--name portainer \
-p 9000:9000 \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
6053537/portainer-ce

安装前提

Centos仅发行版本中的内核支持 Docker;
Docker 运行在 CentOS 7 上时,要求系统为64位、系统内核版本为 3.10 以上;
Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。
安装docker时要先卸载掉旧的docker。

确认系统

首先确认Centos的系统是否为64位,内核版本是否满足上述条件,使用 uname -r 查看当前系统内核版本。

[root@localhost /]# uname -r
3.10.0-693.el7.x86_64

卸载Docker

1. 删除Docker所在目录

rm -rf /etc/docker
rm -rf /run/docker
rm -rf /var/lib/dockershim
rm -rf /var/lib/docker

2. 干掉Docker进程

使用 ps -ef|grep docker 查询docker进程的PID
然后使用 kill -9 pid kill掉docker进程

[root@localhost ~]# ps -ef|grep docker
root      98147      1  0 17:20 ?        00:00:00 /usr/bin/dockerd --data-root /opt/docker -H fd:// --containerd=/run/containerd/containerd.sock
root     103785 102158  0 17:24 pts/0    00:00:00 grep --color=auto docker
[root@localhost ~]# kill -9 98147
[root@localhost ~]# 

3. 卸载Docker相关的包

使用命令 yum list installed | grep docker 查看相关的包

[root@localhost ~]# yum list installed | grep docker
containerd.io.x86_64                  1.6.18-3.1.el7                   @docker-ce-stable
docker-buildx-plugin.x86_64           0.10.2-1.el7                     @docker-ce-stable
docker-ce.x86_64                      3:23.0.1-1.el7                   @docker-ce-stable
docker-ce-cli.x86_64                  1:23.0.1-1.el7                   @docker-ce-stable
docker-ce-rootless-extras.x86_64      23.0.1-1.el7                     @docker-ce-stable
docker-compose-plugin.x86_64          2.16.0-1.el7                     @docker-ce-stable
docker-scan-plugin.x86_64             0.23.0-3.el7                     @docker-ce-stable
[root@localhost ~]# 

把匹配到的包用 yum remove 卸载掉

yum remove \
containerd.io.x86_64 \
docker-buildx-plugin.x86_64 \
docker-ce.x86_64 \
docker-ce-cli.x86_64 \
docker-ce-rootless-extras.x86_64 \
docker-compose-plugin.x86_64 \
docker-scan-plugin.x86_64

开始安装

一键安装

#安装命令
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
#或使用国内 daocloud 一键安装命令
curl -sSL https://get.daocloud.io/docker | sh

Docker安装好后默认路径为 /var/lib/docker ,其下的containers文件夹为容器文件夹,image为镜像文件夹

手动安装

1. 安装依赖软件包

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-util 提供yum-config-manager
devicemapper 存储驱动程序需要依赖 device-mapper-persistent-data 和 lvm2

2. 设置yum源

#官方源(慢)
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
#阿里源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#清华大学源
yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
已加载插件:fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@localhost ~]# 

3. 安装最新版本的 Docker 和 containerd(想安装指定版本看第四步)

#最新的docker社区版
yum install -y docker-ce docker-ce-cli containerd.io

4. 安装指定版本

要安装特定版本的 Docker ,先使用 yum list docker-ce --showduplicates | sort -r 在存储库中列出可用版本,然后选择并安装

[root@localhost ~]# yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror, langpacks
已安装的软件包
可安装的软件包
 * updates: mirrors.ustc.edu.cn
Loading mirror speeds from cached hostfile
 * extras: mirrors.ustc.edu.cn
docker-ce.x86_64            3:23.0.1-1.el7                     docker-ce-stable 
docker-ce.x86_64            3:23.0.1-1.el7                     @docker-ce-stable
docker-ce.x86_64            3:23.0.0-1.el7                     docker-ce-stable 
docker-ce.x86_64            3:20.10.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.23-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.22-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.21-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.20-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.19-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.18-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.17-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.16-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.15-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.14-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.1-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:20.10.13-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.12-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.11-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.10-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:20.10.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.15-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.14-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.1-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.13-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.12-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.11-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.10-3.el7                   docker-ce-stable 
docker-ce.x86_64            3:19.03.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.1-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            18.06.3.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.2.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.1.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            18.03.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.09.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.09.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.2.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.3.ce-1.el7                   docker-ce-stable 
docker-ce.x86_64            17.03.2.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable 
 * base: mirrors.ustc.edu.cn
[root@localhost ~]# 

软件包名称是docker-ce加上第二列版本字符串,从第一个冒号(:)到第一个连字符(-)之间的就是版本号,例:**docker-ce-20.10.9 docker-ce-cli-20.10.9**

#安装指定版本
yum install -y docker-ce-20.10.9 docker-ce-cli-20.10.9 containerd.io

5. 指定docker最终竞选和容器路径(可跳过)

需要注意的时docker在19.xx及之前版本指定路径使用的是 --graph ;而在docker 19.xx之后指定路径时使用的是 data-root实测docker 20.10.21中也可以使用–graph)。
docker指定路径需要修改 /usr/lib/systemd/system/docker.service,
直接使用代码修改(点一次,不小心加多了就去 /usr/lib/systemd/system/docker.service删)

#docker 19.xx 之后
sed -i 's/-H/ \-\-data\-root \/opt\/docker &/' /usr/lib/systemd/system/docker.service
#docker 19.xx及之前
sed -i 's/-H/ \-\-graph \/opt\/docker &/' /usr/lib/systemd/system/docker.service

或者 vi /usr/lib/systemd/system/docker.service
找到 [Service],在 ExecStart中加入 --graph /opt/docker--data-root /opt/docker

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd  --graph /opt/docker -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

或者修改docker的配置文件/etc/docker/daemon.json,效果一样。

#在其中添加
"graph":"/opt/docker"
#或
"data-root":"/opt/docker"

修改完了之后使用 systemctl daemon-reload 重新加载服务

[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# 

6. 启动dokcer

#重启docker
systemctl restart docker
#设置开机启动
systemctl enable docker

扩展:安装portainer

portainer就是一个docker的可视化管理平台,这里的是中文版的

docker pull 6053537/portainer-ce 
docker volume create portainer_data
docker run \
-d \
--name portainer \
-p 9000:9000 \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
6053537/portainer-ce

错误解决

安装依赖软件包报错

[root@localhost /]# yum install -y yum-utils device-mapper-persistent-data lvm2
已加载插件:fastestmirror
base                                                                                     | 3.6 kB  00:00:00     


 One of the configured repositories failed (未知),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Disable the repository, so yum won't use it by default. Yum will then
        just ignore the repository until you permanently enable it again or use
        --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>

     4. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again

解决办法
修改 /etc/yum.repos.d/epel.repo 文件

vi /etc/yum.repos.d/epel.repo

注释metalink,放开baseurl注释,保存

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://repo.huaweicloud.com/epel/7/$basearch
#metalink=https://mirrors.fedoraproject.org/#metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

之后重建yum缓存

yum clean all
yum makecache
#update可选
yum update

安装Docker时报错

e1c94624041b4246aa4cef5262c636c7.png
解决办法

yum erase podman buildah
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43977692/article/details/127492590

智能推荐

JWT(Json Web Token)实现无状态登录_无状态token登录-程序员宅基地

文章浏览阅读685次。1.1.什么是有状态?有状态服务,即服务端需要记录每次会话的客户端信息,从而识别客户端身份,根据用户身份进行请求的处理,典型的设计如tomcat中的session。例如登录:用户登录后,我们把登录者的信息保存在服务端session中,并且给用户一个cookie值,记录对应的session。然后下次请求,用户携带cookie值来,我们就能识别到对应session,从而找到用户的信息。缺点是什么?服务端保存大量数据,增加服务端压力 服务端保存用户状态,无法进行水平扩展 客户端请求依赖服务.._无状态token登录

SDUT OJ逆置正整数-程序员宅基地

文章浏览阅读293次。SDUT OnlineJudge#include<iostream>using namespace std;int main(){int a,b,c,d;cin>>a;b=a%10;c=a/10%10;d=a/100%10;int key[3];key[0]=b;key[1]=c;key[2]=d;for(int i = 0;i<3;i++){ if(key[i]!=0) { cout<<key[i.

年终奖盲区_年终奖盲区表-程序员宅基地

文章浏览阅读2.2k次。年终奖采用的平均每月的收入来评定缴税级数的,速算扣除数也按照月份计算出来,但是最终减去的也是一个月的速算扣除数。为什么这么做呢,这样的收的税更多啊,年终也是一个月的收入,凭什么减去12*速算扣除数了?这个霸道(不要脸)的说法,我们只能合理避免的这些跨级的区域了,那具体是那些区域呢?可以参考下面的表格:年终奖一列标红的一对便是盲区的上下线,发放年终奖的数额一定一定要避免这个区域,不然公司多花了钱..._年终奖盲区表

matlab 提取struct结构体中某个字段所有变量的值_matlab读取struct类型数据中的值-程序员宅基地

文章浏览阅读7.5k次,点赞5次,收藏19次。matlab结构体struct字段变量值提取_matlab读取struct类型数据中的值

Android fragment的用法_android reader fragment-程序员宅基地

文章浏览阅读4.8k次。1,什么情况下使用fragment通常用来作为一个activity的用户界面的一部分例如, 一个新闻应用可以在屏幕左侧使用一个fragment来展示一个文章的列表,然后在屏幕右侧使用另一个fragment来展示一篇文章 – 2个fragment并排显示在相同的一个activity中,并且每一个fragment拥有它自己的一套生命周期回调方法,并且处理它们自己的用户输_android reader fragment

FFT of waveIn audio signals-程序员宅基地

文章浏览阅读2.8k次。FFT of waveIn audio signalsBy Aqiruse An article on using the Fast Fourier Transform on audio signals. IntroductionThe Fast Fourier Transform (FFT) allows users to view the spectrum content of _fft of wavein audio signals

随便推点

Awesome Mac:收集的非常全面好用的Mac应用程序、软件以及工具_awesomemac-程序员宅基地

文章浏览阅读5.9k次。https://jaywcjlove.github.io/awesome-mac/ 这个仓库主要是收集非常好用的Mac应用程序、软件以及工具,主要面向开发者和设计师。有这个想法是因为我最近发了一篇较为火爆的涨粉儿微信公众号文章《工具武装的前端开发工程师》,于是建了这么一个仓库,持续更新作为补充,搜集更多好用的软件工具。请Star、Pull Request或者使劲搓它 issu_awesomemac

java前端技术---jquery基础详解_简介java中jquery技术-程序员宅基地

文章浏览阅读616次。一.jquery简介 jQuery是一个快速的,简洁的javaScript库,使用户能更方便地处理HTML documents、events、实现动画效果,并且方便地为网站提供AJAX交互 jQuery 的功能概括1、html 的元素选取2、html的元素操作3、html dom遍历和修改4、js特效和动画效果5、css操作6、html事件操作7、ajax_简介java中jquery技术

Ant Design Table换滚动条的样式_ant design ::-webkit-scrollbar-corner-程序员宅基地

文章浏览阅读1.6w次,点赞5次,收藏19次。我修改的是表格的固定列滚动而产生的滚动条引用Table的组件的css文件中加入下面的样式:.ant-table-body{ &amp;amp;::-webkit-scrollbar { height: 5px; } &amp;amp;::-webkit-scrollbar-thumb { border-radius: 5px; -webkit-box..._ant design ::-webkit-scrollbar-corner

javaWeb毕设分享 健身俱乐部会员管理系统【源码+论文】-程序员宅基地

文章浏览阅读269次。基于JSP的健身俱乐部会员管理系统项目分享:见文末!

论文开题报告怎么写?_开题报告研究难点-程序员宅基地

文章浏览阅读1.8k次,点赞2次,收藏15次。同学们,是不是又到了一年一度写开题报告的时候呀?是不是还在为不知道论文的开题报告怎么写而苦恼?Take it easy!我带着倾尽我所有开题报告写作经验总结出来的最强保姆级开题报告解说来啦,一定让你脱胎换骨,顺利拿下开题报告这个高塔,你确定还不赶快点赞收藏学起来吗?_开题报告研究难点

原生JS 与 VUE获取父级、子级、兄弟节点的方法 及一些DOM对象的获取_获取子节点的路径 vue-程序员宅基地

文章浏览阅读6k次,点赞4次,收藏17次。原生先获取对象var a = document.getElementById("dom");vue先添加ref <div class="" ref="divBox">获取对象let a = this.$refs.divBox获取父、子、兄弟节点方法var b = a.childNodes; 获取a的全部子节点 var c = a.parentNode; 获取a的父节点var d = a.nextSbiling; 获取a的下一个兄弟节点 var e = a.previ_获取子节点的路径 vue