參考
- https://www.sysgeek.cn/install-docker-ubuntu/ (主要參考)
- https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/ (清華映象站)
- https://blog.csdn.net/dragonstrong/article/details/118915771 (ubuntu 設定代理,需要梯子開啟區域網訪問,並指定埠號)
- https://blog.csdn.net/sxzlc/article/details/105922314 (telnet 驗證主機埠是否正常訪問)
- https://blog.csdn.net/Fengdf666/article/details/140218342 (解決docker官方無法正常訪問,切換docker下載為阿里源)
- https://juejin.cn/post/7135739035158315022
- https://blog.csdn.net/qq_45558497/article/details/123970473 (設定 docker 開機自啟)
環境
軟體/系統 | 版本 | 說明 |
---|---|---|
VMware | Workstation 16 Pro 16.2.4 build-20089737 | |
Ubuntu Server | Ubuntu Server 24.04 LTS | |
net-tools | 2.10-0.1ubuntu4 | 軟體包 (檢視虛擬機器ip使用) |
nano | 7.2-2build1 | 軟體包(編輯器) |
apt-transport-https | 2.7.14build2 | 軟體包 |
curl | 8.5.0-2ubuntu10.3 | 軟體包 |
docker-ce | 5:27.2.0-1 | 軟體包 |
docker-ce-cli | 5:27.2.0-1 | 軟體包 |
containerd.io | 1.7.21-1 | 軟體包 |
docker-compose-plugin | 2.29.2-1 | 軟體包 |
正文
-
設定軟體源為國內源(此處使用清華源)
# 備份源 sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.back # 編輯源 sudo nano /etc/apt/sources.list.d/ubuntu.sources
將下面的內容填充到
ubuntu.sources
Types: deb URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu Suites: noble noble-updates noble-backports Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg # 預設註釋了原始碼映象以提高 apt update 速度,如有需要可自行取消註釋 # Types: deb-src # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu # Suites: noble noble-updates noble-backports # Components: main restricted universe multiverse # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg # 以下安全更新軟體源包含了官方源與映象站配置,如有需要可自行修改註釋切換 Types: deb URIs: http://security.ubuntu.com/ubuntu/ Suites: noble-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg # Types: deb-src # URIs: http://security.ubuntu.com/ubuntu/ # Suites: noble-security # Components: main restricted universe multiverse # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg # 預釋出軟體源,不建議啟用 # Types: deb # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu # Suites: noble-proposed # Components: main restricted universe multiverse # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg # # Types: deb-src # # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu # # Suites: noble-proposed # # Components: main restricted universe multiverse # # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
-
更新軟體包並安裝必要軟體
由於備份了
ubuntu.sources
為ubuntu.sources.back
所以後續執行 apt 相關命令時會提示N: Ignoring file 'ubuntu.sources.back' in directory '/etc/apt/sources.list.d/' as it has an invalid filename extension
,忽視即可。sudo apt update sudo apt install apt-transport-https curl
-
匯入阿里雲官方 GPG 金鑰
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
-
新增阿里雲源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
-
更新源
sudo apt update
-
安裝
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
-
檢查執行狀態
ubuntu@ubuntu:~$ sudo systemctl is-active docker
顯示如下為正常
active
-
設定 docker 開機啟動
systemctl enable docker.service