mobian trixie 安裝 docker

有梦不难發表於2024-10-28

手機刷了 mobian 想安裝 docker,記錄安裝過程中的一些問題

1. 更新軟體包列表

sudo apt-get update

2. 安裝依賴包

sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release

3. 新增 Docker 的官方GPG金鑰

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

4. 設定 Docker 的apt儲存庫

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

由於我當前系統的版本是 debian trixie,docker 官方暫時沒有這個版本的軟體包,所以把上述命令中的 $(lsb_release -cs) 改為 bookworm

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  bookworm stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

5. 更新軟體包列表

sudo apt-get update

6. 安裝 Docker Engine

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

7. 配置國內的 docker 映象源

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://hub.atomgit.com"]
}
EOF

8. 重啟 docker 服務

systemctl daemon-reload
systemctl restart docker

這時重啟出現報錯

dockerd 命令檢視報錯資訊

WARN[2024-10-28T00:41:21.508636677+06:00] failed to find iptables                       error="exec: \"iptables\": executable file not found in $PATH"
INFO[2024-10-28T00:41:21.512342948+06:00] stopping event stream following graceful shutdown  error="<nil>" module=libcontainerd namespace=moby
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to register "bridge" driver: failed to create NAT chain DOCKER: iptables not found

看報錯資訊是沒有找到 iptables,用 sudo apt install iptables 命令安裝 iptables 後重啟依然失敗,不知道是不是因為沒有設定環境變數,但是參考其他博主用下面兩條命令解決了

https://www.cnblogs.com/zuiyixin/p/17169350.html

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

#啟動命令
sudo service docker start

9.驗證 Docker 是否正常運作

sudo docker run hello-world