Centos7安裝docker、docker-compose實踐過程
一、卸載舊版Docker
1、查詢是否安裝過舊版
yum list installed | grep docker
沒有出現(xiàn)內容就表示沒有安裝過docker
出現(xiàn)以下內容代表安裝過docker,若需要安裝最新版則進行卸載
2、查詢Docker狀態(tài),目前是運行狀態(tài)
systemctl status docker #查詢docker狀態(tài)
當前docker正在運行需要停止后再進行卸載
systemctl stop docker #停止docker
停止docker服務后,出現(xiàn)以下警告信息,docker在關閉狀態(tài)下被訪問會觸發(fā)自動喚醒機制,下次再執(zhí)行任意的docker命令會直接啟動docker服務
再次查詢docker狀態(tài)為停止狀態(tài)
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
#刪除docker相關軟件包 yum remove -y docker*
4、刪除Docker相關的鏡像和容器
docker相關的鏡像和容器,在 /var/lib 下
rm -rf /var/lib/docker #刪除/var/lib下的docker文件夾
運行后再次查詢已經(jīng)沒有docker文件夾了
二、安裝Docker
1、安裝yum-utils工具包并設置阿里云鏡像
#安裝yum-utils工具 yum install -y yum-utils device-mapper-persistent-data lvm2
如果安裝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
2、查看所有Docker版本
yum list docker-ce --showduplicates | sort -r
3、安裝指定版本Docker
例如安裝26.0.2-1.el7版本
注意版本號只要"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使用前準備
1、啟動Docker服務
systemctl start docker
2、停止Docker服務
systemctl stop docker
停止docker服務后,出現(xiàn)以上警告信息,docker在關閉狀態(tài)下被訪問會觸發(fā)自動喚醒機制,下次再執(zhí)行任意的docker命令會直接啟動docker服務,如果希望docker不會觸發(fā)訪問自動喚醒機制,停止docker服務時執(zhí)行以下命令
systemctl stop docker.socket
3、查看Docker服務狀態(tài)
systemctl status docker
以下是docker服務運行狀態(tài)
以下是docker服務停止狀態(tài)
4、設置Docker服務開機自啟動
systemctl enable docker
四、docker-compose安裝
1、下載Docker Compose二進制文件
# 下載Docker Compose二進制文件 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í)行權限 sudo chmod +x /usr/local/bin/docker-compose
或者使用以下離線安裝
2、先到GitHub下載docker-compose
3、將下載好的文件上傳到Linux
將docker-compose文件上傳到/usr/local/bin下,并改名為docker-compose
給docker-compose添加可執(zhí)行權限
chmod +x /usr/local/bin/docker-compose
4、查看版本號
docker-compose version
總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
docker-compose創(chuàng)建網(wǎng)橋,添加子網(wǎng),刪除網(wǎng)卡的實現(xiàn)
這篇文章主要介紹了docker-compose創(chuàng)建網(wǎng)橋,添加子網(wǎng),刪除網(wǎng)卡的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03docker-compose搭建mongodb、mysql的詳細過程
這篇文章主要介紹了docker-compose搭建mongodb、mysql的詳細過程,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-11-11