何小豆儿在此 发表于 2025-1-2 20:43:29

Centos 7安装docker、docker-compose教程

一、卸载旧版Docker

1、查询是否安装过旧版

yum list installed | grep docker
没有出现内容就表现没有安装过docker
https://i-blog.csdnimg.cn/direct/32a8edff821c4342a0343fcf47f0b8d3.png
出现以下内容代表安装过docker,若需要安装最新版则进行卸载
https://i-blog.csdnimg.cn/direct/61a472d8ecaf4a7c9a7bc9bfda99e62e.png
2、查询Docker状态,现在是运行状态

systemctl status docker
#查询docker状态
当前docker正在运行需要停止后再进行卸载
https://i-blog.csdnimg.cn/direct/a18b753ba6f747ed80c8f8995db84bb5.png
systemctl stop docker
#停止docker
停止docker服务后,出现以下警告信息,docker在关闭状态下被访问会触发自动唤醒机制,下次再实行任意的docker下令会直接启动docker服务
https://i-blog.csdnimg.cn/direct/fef867abdf8649b2a3fa23d3ac1194e1.png
再次查询docker状态为停止状态
https://i-blog.csdnimg.cn/direct/d04e30ab00fc41b79ad03f489fb2da64.png
3、删除安装过Docker的相干包

#删除命令如下
yum -y 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
https://i-blog.csdnimg.cn/direct/471e7702f3604b42aee8e2f4a41a47a1.png
#删除docker相关软件包
yum remove -y docker*
https://i-blog.csdnimg.cn/direct/8b075df4ac4440cab0de72689174dcf5.png
4、删除Docker相干的镜像和容器

docker相干的镜像和容器,在 /var/lib 下
https://i-blog.csdnimg.cn/direct/720f1f5de0d94397a9a4f0c92e4670ab.png
rm -rf /var/lib/docker#删除/var/lib下的docker文件夹
运行后再次查询已经没有docker文件夹了
https://i-blog.csdnimg.cn/direct/96ee8ff620414176a94bf4b996d27b0e.png
二、安装Docker

1、安装yum-utils工具包并设置阿里云镜像

#安装yum-utils工具
yum install -y yum-utils device-mapper-persistent-data lvm2
https://i-blog.csdnimg.cn/direct/7d0b1b25187c4f2c88c3d128ed4a73d2.png
如果安装yum-utils工具时表现以下内容时,分析安装失败,国外镜像源封锁增强,需要更换国内镜像源后才能安装 点击更改镜像源
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"


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. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

   4. Disable the repository permanently, 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>
      or
            subscription-manager repos --disable=<repoid>

   5. 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 find a valid baseurl for repo: base/7/x86_64
设置阿里云镜像
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
https://i-blog.csdnimg.cn/direct/93f849e400824193bca1045007d9ba0e.png
2、检察所有Docker版本

yum list docker-ce --showduplicates | sort -r
https://i-blog.csdnimg.cn/direct/995b25f19cfb471a86dc611a7523e2b7.png
3、安装指定版本Docker

例如安装26.0.2-1.el7版本
https://i-blog.csdnimg.cn/direct/02084b39c6db4cbbae889d648b840323.png
   注意版本号只要"3:"背面的那部分
yum install -y docker-ce-26.0.2-1.el7 docker-ce-cli-26.0.2-1.el7 containerd.io
4、安装最新版Docker

yum install -ydocker-ce docker-ce-cli containerd.io
   在下令行中 --allowerasing 参数允许更换冲突的软件包,可以不加
yum install -y --allowerasing docker-ce docker-ce-cli containerd.io
https://i-blog.csdnimg.cn/direct/0ea96215c8e7494bbfbd517066f42865.png
三、Docker利用前准备

1、启动Docker服务

systemctl start docker
2、停止Docker服务

systemctl stop docker
https://i-blog.csdnimg.cn/direct/fef867abdf8649b2a3fa23d3ac1194e1.png
   停止docker服务后,出现以上警告信息,docker在关闭状态下被访问会触发自动唤醒机制,下次再实行任意的docker下令会直接启动docker服务,如果盼望docker不会触发访问自动唤醒机制,停止docker服务时实行以下下令
systemctl stop docker
.socket 3、检察Docker服务状态

systemctl status docker
   以下是docker服务运行状态
https://i-blog.csdnimg.cn/direct/1da77deada9541b2950ad3cb39257d6f.png
   以下是docker服务停止状态
https://i-blog.csdnimg.cn/direct/a3aae073f9f449e9b3c79d9972612d57.png
4、设置Docker服务开机自启动

systemctl enable docker
四、docker-compose安装

1、先到GitHub下载docker-compose

docker-compose下载地址
https://i-blog.csdnimg.cn/direct/d382b884e37d40e1bf9e56ed2f331d3b.png
2、将下载好的文件上传到Linux

将docker-compose文件上传到/usr/local/bin下,并改名为docker-compose
https://i-blog.csdnimg.cn/direct/6867a8ecae554c8aa24973593fe898df.png
给docker-compose添加可实行权限
chmod +x /usr/local/bin/docker-compose
3、检察版本号

docker-compose version
https://i-blog.csdnimg.cn/direct/2330092ae7e04c549190e14ce3606f4a.png

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Centos 7安装docker、docker-compose教程