安裝 Docker-yum-阿里雲鏡像

Architecture: x86-64

Operating System: Alibaba Cloud Linux 3 (Soaring Falcon)

Docker Engine - Community 26.0.0

---

 

序章

官方文檔:Install Docker Engine on CentOS

https://docs.docker.com/engine/install/centos/

注,Alibaba Cloud Linux 3 是一個 CentOS 系統。

 

阿里雲 Docker CE 鏡像

https://developer.aliyun.com/mirror/docker-ce

 

說明,

根據官網文檔 也可以安裝,但考慮到 下載速度,最後選擇了 阿里雲鏡像 進行安裝。

說明,

安裝全程使用 root 賬號。

 

安裝步驟

打開 阿里雲 Docker CE 鏡像 頁面:

因爲 Alibaba Cloud Linux 3 是一個 CentOS 系統,選擇 配置方法中的【CentOS 7(使用 yum 進行安裝)】:

阿里雲鏡像 的 CentOS 7 完整命令:

# step 1: 安裝必要的一些系統工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加軟件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# Step 4: 更新並安裝Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 開啓Docker服務
sudo service docker start

 

準備

Alibaba Cloud Linux 3 已安裝 yum-utils 等,故,省略第一步。

執行 第二步:

# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

此時,/etc/yum.repos.d 目錄下出現一個 docker-ce.repo 文件。

順利。

執行 第三步:

# sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo

順利。

 

執行 第四步:

# yum makecache fast

出現錯誤:

yum makecache: error: argument timer: invalid choice: 'fast' (choose from 'timer')

更加 參考文檔#1 解決:Alibaba Cloud Linux 3 是 CentOS 8,而不是 CentOS 7。

換爲 執行下面的命令:

# dnf makecache

順利。

 

yum 查找 docker:

可以看到 已經有 docker-ce、docker-ce-cli 兩個包了。

 

yum 查看 docker-ce 的信息:

# yum info docker-ce
Last metadata expiration check: 0:01:27 ago on Wed 27 Mar 2024 11:16:53 AM CST.
Available Packages
Name         : docker-ce
Epoch        : 3
Version      : 26.0.0
Release      : 1.el8
Architecture : x86_64
Size         : 27 M
Source       : docker-ce-26.0.0-1.el8.src.rpm
Repository   : docker-ce-stable
Summary      : The open-source application container engine
URL          : https://www.docker.com
License      : ASL 2.0
Description  : Docker is a product for you to build, ship and run any application as a
             : lightweight container.
             :
             : Docker containers are both hardware-agnostic and platform-agnostic. This means
             : they can run anywhere, from your laptop to the largest cloud compute instance
             : and everything in between - and they don't require you to use a particular
             : language, framework or packaging system. That makes them great building blocks
             : for deploying and scaling web apps, databases, and backend services without
             : depending on a particular stack or provider.

 

安裝

執行 第五步:安裝

# yum -y install docker-ce
Last metadata expiration check: 0:04:10 ago on Wed 27 Mar 2024 11:16:53 AM CST.
Dependencies resolved.

省略

Install  12 Packages

省略

Installed:
  containerd.io-1.6.28-3.2.el8.x86_64                 docker-buildx-plugin-0.13.1-1.el8.x86_64        docker-ce-3:26.0.0-1.el8.x86_64            docker-ce-cli-1:26.0.0-1.el8.x86_64
  docker-ce-rootless-extras-26.0.0-1.el8.x86_64       docker-compose-plugin-2.25.0-1.el8.x86_64       fuse-overlayfs-1.11-1.0.1.al8.x86_64       fuse3-3.3.0-16.al8.x86_64
  fuse3-libs-3.3.0-16.al8.x86_64                      libcgroup-0.41-19.2.al8.x86_64                  libslirp-4.4.0-1.al8.x86_64                slirp4netns-1.2.0-2.al8.x86_64

Complete!

順利。

 

啓動

執行 第六步:查看 Docker (服務器) 運行狀態,並啓動。

# systemctl status docker # 查看狀態

# systemctl start docker # 啓動

啓動後的狀態顯示爲 active (running)

默認 開機啓動。

ben發佈於博客園

查看 docker 服務的進程信息:

# ps -ef | grep docker
root      302148       1  0 11:22 ?        00:00:10 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

查看其它信息:

# whereis docker
docker: /usr/bin/docker /etc/docker /usr/libexec/docker /usr/share/man/man1/docker.1.gz

# whereis dockerd
dockerd: /usr/bin/dockerd /usr/share/man/man8/dockerd.8.gz

# ls /usr/bin | grep docker
docker
dockerd
dockerd-rootless-setuptool.sh
dockerd-rootless.sh
docker-proxy
rootlesskit-docker-proxy

ben發佈於博客園

檢查配置:/etc/docker 目錄

此時,目錄下什麼也沒有。

# cd /etc/docker/
[root@--- docker]# pwd
/etc/docker
[root@--- docker]# ll
total 0

ben發佈於博客園

查看安裝的 docker 版本:Server, Client 都是 26.0.0。

# docker version
Client: Docker Engine - Community
 Version:           26.0.0
 API version:       1.45
 Go version:        go1.21.8
 Git commit:        2ae903e
 Built:             Wed Mar 20 15:19:04 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.0.0
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       8b79278
  Built:            Wed Mar 20 15:17:57 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

ben發佈於博客園

驗證:運行 hello-world 鏡像

執行 下面的命令:

# docker run hello-world

本地沒有,先拉取,拉取後,運行。

截圖:

順利。驗證通過。

 

使用 docker images 命令,可以看到拉取了一個名爲 hello-world 的鏡像。

# docker images
REPOSITORY       TAG       IMAGE ID       CREATED         SIZE
hello-world      latest    d2c94e258dcb   10 months ago   13.3kB

 

至此,安裝完畢。

ben發佈於博客園

本文涉及命令

  1. yum-config-manager --add-repo ...
  2. sed -i ...
  3. yum makecache fast
  4. dnf makecache
  5. yum search docker
  6. yum info docker-ce
  7. yum -y install docker-ce
  8. systemctl status docker
  9. systemctl start docker
  10. docker version
  11. docker run hello-world
  12. docker images

 

說明,

dnf 就是 yum,新版本的 yum。

# man yum

 

說明,

sed 命令,sed - stream editor for filtering and transforming text。

# man sed

-i 選項:

-i[SUFFIX], --in-place[=SUFFIX]

              edit files in place (makes backup if SUFFIX supplied)

菜鳥教程:

語法 sed [-hnV][-e<script>][-f<script文件>][文本文件]

  • i :插入, i 的後面可以接字串,而這些字串會在新的一行出現(目前的上一行);

 

ben發佈於博客園

---END---

 

本文鏈接:

https://www.cnblogs.com/luo630/p/18099590

ben發佈於博客園

參考資料

1、Linux - Centos 8 執行 yum makecache fast 報錯

2022-05-15

https://developer.aliyun.com/article/921972

2、菜鳥教程:Docker 教程

https://www.runoob.com/docker/docker-tutorial.html

可以學習 其它 docker 命令的基本操作,Dockerfile 的製作;

可以配置自己的 docker hub 地址,比如,阿里雲的;

3、菜鳥教程:Linux sed 命令

https://www.runoob.com/linux/linux-comm-sed.html

4、

 

ben發佈於博客園

ben發佈於博客園

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章