Centos7安裝docker、docker-compose實(shí)踐過(guò)程
一、卸載舊版Docker
1、查詢是否安裝過(guò)舊版
yum list installed | grep docker
沒(méi)有出現(xiàn)內(nèi)容就表示沒(méi)有安裝過(guò)docker

出現(xiàn)以下內(nèi)容代表安裝過(guò)docker,若需要安裝最新版則進(jìn)行卸載

2、查詢Docker狀態(tài),目前是運(yùn)行狀態(tài)
systemctl status docker #查詢docker狀態(tài)
當(dāng)前docker正在運(yùn)行需要停止后再進(jìn)行卸載

systemctl stop docker #停止docker
停止docker服務(wù)后,出現(xiàn)以下警告信息,docker在關(guān)閉狀態(tài)下被訪問(wèn)會(huì)觸發(fā)自動(dòng)喚醒機(jī)制,下次再執(zhí)行任意的docker命令會(huì)直接啟動(dòng)docker服務(wù)

再次查詢docker狀態(tài)為停止?fàn)顟B(tài)

3、刪除安裝過(guò)Docker的相關(guān)包
#刪除命令如下 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

#刪除docker相關(guān)軟件包 yum remove -y docker*

4、刪除Docker相關(guān)的鏡像和容器
docker相關(guān)的鏡像和容器,在 /var/lib 下

rm -rf /var/lib/docker #刪除/var/lib下的docker文件夾
運(yùn)行后再次查詢已經(jīng)沒(méi)有docker文件夾了

二、安裝Docker
1、安裝yum-utils工具包并設(shè)置阿里云鏡像
#安裝yum-utils工具 yum install -y yum-utils device-mapper-persistent-data lvm2

如果安裝yum-utils工具時(shí)顯示以下內(nèi)容時(shí),說(shuō)明安裝失敗,國(guó)外鏡像源封鎖加強(qiáng),需要更換國(guó)內(nèi)鏡像源后才能安裝 點(diǎn)擊更改鏡像源
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; 未知的錯(cuò)誤"
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
設(shè)置阿里云鏡像
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2、查看所有Docker版本
yum list docker-ce --showduplicates | sort -r

3、安裝指定版本Docker
例如安裝26.0.2-1.el7版本

注意版本號(hào)只要"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 -y docker-ce docker-ce-cli containerd.io
在命令行中 --allowerasing 參數(shù)允許替換沖突的軟件包,可以不加
yum install -y --allowerasing docker-ce docker-ce-cli containerd.io

三、Docker使用前準(zhǔn)備
1、啟動(dòng)Docker服務(wù)
systemctl start docker
2、停止Docker服務(wù)
systemctl stop docker

停止docker服務(wù)后,出現(xiàn)以上警告信息,docker在關(guān)閉狀態(tài)下被訪問(wèn)會(huì)觸發(fā)自動(dòng)喚醒機(jī)制,下次再執(zhí)行任意的docker命令會(huì)直接啟動(dòng)docker服務(wù),如果希望docker不會(huì)觸發(fā)訪問(wèn)自動(dòng)喚醒機(jī)制,停止docker服務(wù)時(shí)執(zhí)行以下命令
systemctl stop docker.socket
3、查看Docker服務(wù)狀態(tài)
systemctl status docker
以下是docker服務(wù)運(yùn)行狀態(tài)

以下是docker服務(wù)停止?fàn)顟B(tài)

4、設(shè)置Docker服務(wù)開(kāi)機(jī)自啟動(dòng)
systemctl enable docker
四、docker-compose安裝
1、下載Docker Compose二進(jìn)制文件
# 下載Docker Compose二進(jìn)制文件 sudo curl -L "https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose # 賦予執(zhí)行權(quán)限 sudo chmod +x /usr/local/bin/docker-compose
或者使用以下離線安裝
2、先到GitHub下載docker-compose

3、將下載好的文件上傳到Linux
將docker-compose文件上傳到/usr/local/bin下,并改名為docker-compose

給docker-compose添加可執(zhí)行權(quán)限
chmod +x /usr/local/bin/docker-compose
4、查看版本號(hào)
docker-compose version

總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Docker 拉取鏡像超時(shí)(親測(cè) 3 個(gè)有效鏡像源 + 避坑指南)
Docker 默認(rèn)鏡像源在國(guó)外,國(guó)內(nèi)訪問(wèn)經(jīng)常抽風(fēng),常規(guī)操作應(yīng)該是換國(guó)內(nèi)鏡像源,本文就來(lái)介紹一下三個(gè)國(guó)內(nèi)穩(wěn)定源,具有一定的參考價(jià)值,感興趣的可以了解一下2025-08-08
如何解決對(duì)Docker容器內(nèi)存限制警告或未實(shí)際限制的問(wèn)題
這篇文章主要介紹了如何解決對(duì)Docker容器內(nèi)存限制警告或未實(shí)際限制的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04
利用docker-compsoe部署前后端分離的項(xiàng)目方法
這篇文章主要介紹了利用docker-compsoe部署前后端分離的項(xiàng)目方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
使用Docker run的選項(xiàng)以覆蓋Dockerfile中的設(shè)置詳解
今天小編就為大家分享一篇關(guān)于使用Docker run的選項(xiàng)以覆蓋Dockerfile中的設(shè)置詳解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-10-10
Linux執(zhí)行Docker命令提示Get Permission Denied的解決方案
這篇文章主要介紹了Linux執(zhí)行Docker命令提示Get Permission Denied的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-06-06
docker部署安裝jenkins的實(shí)現(xiàn)步驟
本文主要介紹了docker部署安裝jenkins的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12
docker部署fastapi的實(shí)現(xiàn)步驟
本文主要介紹了docker部署fastapi的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03
Docker Compose 與 Harbor 私有倉(cāng)庫(kù)詳解
本文將探討Docker Compose多容器編排工具與Harbor企業(yè)級(jí)私有倉(cāng)庫(kù)的核心技術(shù),幫助讀者掌握從容器管理到鏡像安全存儲(chǔ)的完整解決方案,感興趣的朋友一起看看吧2025-06-06

