How to Install Docker in Ubuntu

如何在 Ubuntu 安裝 Docker，使用官方推薦方式

移除舊版本的 Docker

避免與原先的版本衝突，建議把原本舊安裝過的 docker 移除掉

Copy
sudo apt-get remove docker docker-engine docker.io containerd runc

手動去檢查是否完全刪除原本舊有的 docker

Copy
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

使用 apt-get 安裝

設定 repository

Copy
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安裝 Docker Engine

透過 apt-get 安裝

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

確認是否安裝成功

Copy
sudo docker run hello-world