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

智能推荐

UE4 C++PhysicalSurface(_杰森大师)_c2039"surfacetype": 不是 "tweakobjectptr<uphysicalma-程序员宅基地

文章浏览阅读888次。先在项目设置的Physics中设置在内容浏览器增加物理材质在里面进行定义进入人物的physics中将自己创的定义进去这样角色就拥有了物理材质,接下来进入程序加上互动。呈现点效果进入项目.h文件中增加宏定义,=//就是给这两个物理材质增加个假名,等下容易进行调用#define SURFACE_FLESHDEFAULT SurfaceType1#define SU..._c2039"surfacetype": 不是 "tweakobjectptr

Java配合Vue实现微信公众号自动登录_java vue 微信公众号openid自动登录-程序员宅基地

文章浏览阅读569次。话不多说,直接进入正题.首先,要在微信公众平台注册一个公众账号,我这边是用的测试账号.有了账号之后进入微信公众平台获取appID和appsecret以供调用接口.微信开发者文档地址:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html首先判断coo..._java vue 微信公众号openid自动登录

执行mysql的sql语句报错“Fatal error encountered during command execution”_fatal error encountered during command execution. -程序员宅基地

文章浏览阅读1.7k次。问题描述:mysql执行还有自定义参数的sql语句会报错“Fatal error encountered during command execution”(执行命令时遇到的致命错误)问题原因:发帖的时候刚用msql不久,公司项目里遇见的,好像是mysql执行非过程语句步能使用变量吧,有清楚的朋友可以评论补充一下解决方法:数据库连接字符出添加”Allow User Variables=T..._fatal error encountered during command execution. csdn

WEB组态 工业物联网平台 大屏展示_wed组态图片-程序员宅基地

文章浏览阅读3.2k次。工业互联网涉及很多领域:物联网、IoT、5G、数字孪生、边缘计算、工业4.0、智能制造等概念。其中,工业生产可视化将成为新一轮制造革命的核心竞争力。工业企业中生产线处于高速运转,由工业设备所产生、采集和处理的数据量远大于企业中计算机和人工产生的数据,生产线的高速运转则对数据的实时性要求也更高。破解这些大数据就是企业在新一轮制造革命中赢得竞争力的钥匙。因此,工业生产可视化系统是工业制造业的最佳选..._wed组态图片

Cocos Creator 热更新工具BUG:重启游戏后热更新无效!(已解决)_cocos热更新成功后还是旧的-程序员宅基地

文章浏览阅读2.6k次。问题:cocos热更新成功但是没变化?热更新资源未生效?在Cocos Creator v2.3.1中,使用扩展商店里的热更新工具实现热更新,热更新完毕后自动重启游戏,此时更新可以成功,但是重启游戏后热更新的效果无效了!但是版本却是最新的!_cocos热更新成功后还是旧的

React项目自定义滚动条的方案回顾_react 自定义scrollbar样式兼容性-程序员宅基地

文章浏览阅读5.9k次,点赞2次,收藏2次。更改原生样式chrome提供了良好的css接口,用于更改原生滚动条的样式,主要是下面两个:::-webkit-scrollbar //滚动条整体部分,可以设置宽度啥的::-webkit-scrollbar-thumb //滚动的滑块虽然基本实现了设计稿的样子,但这里会有两个问题无法实现:设计稿中要求滚动条距离右边边框有4px间距滚动条要悬浮于内容之上firefox:无接口,任性..._react 自定义scrollbar样式兼容性

随便推点

主轴优化matlab程序,基于MATLAB的机床主轴结构优化设计-程序员宅基地

文章浏览阅读809次。收稿日期: 2012 年 3 月 基于 MATLAB 的机床主轴结构优化设计 刘红娟宝鸡文理学院 摘要: 介绍了机床主轴的结构,建立了以质量最轻为目标函数的优化模型,运用 MATLAB 优化工具箱中的fmincon 函数对其进行优化设计。通过对已有的机床主轴实例进行优化求解和分析,对比优化前后的数据信息,表明优化之后的机床主轴质量更轻,且编程简单,设计效率高。最后绘出了实例的各设计变量和目标函数之..._机床主轴优化设计matlab程序

Python-openpyxl对Excel的操作(获取总行列数,获取某行值,获取某列值,设置单元格值)_python get excel表的行与列值-程序员宅基地

文章浏览阅读3.5k次,点赞3次,收藏10次。转载至https://www.cnblogs.com/dmtz/p/11091090.htmlfrom openpyxl import *class excel(): def __init__(self,file): self.file = file self.wb = load_workbook(self.file) sheets = self.wb.get_sheet_names() self.sheet = sheets_python get excel表的行与列值

OpenCV学习笔记之针对二值图像的边缘光滑处理(突出部消除)_opencv 凸出明显的地方删除-程序员宅基地

文章浏览阅读4.5w次,点赞14次,收藏147次。处理代码分为两部分,第一部分用于去除边缘的突出部,第二部分用于边缘光滑。具体如下所示1.去除边缘突出部//去除二值图像边缘的突出部//uthreshold、vthreshold分别表示突出部的宽度阈值和高度阈值//type代表突出部的颜色,0表示黑色,1代表白色 void delete_jut(Mat& src, Mat& dst, int uthreshold, int vthre_opencv 凸出明显的地方删除

SpringBoot--------核心配置(二)_$module_dir$ application.properties-程序员宅基地

文章浏览阅读1.1k次。BEGINJava面试题全集84集系列:https://www.bilibili.com/video/av29503459?from=search&seid=6567704966922691267Java高频面试题-尚硅谷-Java面试题第一季:https://www.bilibili.com/video/av37602130?from=search&se..._$module_dir$ application.properties

Matlab对灰度图像的频域进行高通滤波和低通滤波_灰度图像频域处理-程序员宅基地

文章浏览阅读1w次,点赞11次,收藏114次。1. 要求对灰度图像进行离散傅里叶变换(Discrete Fourier Transfom, DFT)变换,在频域上分别使用理想的高通和低通滤波器进行滤波,显示滤波后的频域图像,以及逆离散傅里叶变换(Inverse Discrete Fourier Transfom, IDFT)变换后的空域图像,观察振铃现象。2. 读取灰度图像这里读取matlab自带的“摄影师”灰度图像%% 读取图像x = imread('cameraman.tif');figure, imshow(x), titl_灰度图像频域处理

安科瑞智慧安全用电云平台【无人化数据监控 远程控制 运维管理】-程序员宅基地

文章浏览阅读1.3k次,点赞36次,收藏23次。安全用电监测预警系统通过物联网技术对电气引发火灾的主要因素(导线温度、电流、电压和漏电流)进行不间断的数据跟踪与统计分析,实时发现电气线路和用电设备存在的安全隐患(如:线缆温度异常、短路、过载、过压、欠压及漏电等),有效防止电气火灾的发生。

推荐文章

热门文章

相关标签