在Ubuntu上安裝Docker有兩種方法:通過官方倉庫安裝或者通過腳本一鍵安裝。
方法一:通過官方倉庫安裝Docker
更新系統軟件包列表:
sudo apt update
安裝所需的依賴包:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
添加Docker的官方GPG密鑰:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
添加Docker的APT倉庫:
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
echo "deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
更新軟件包列表:
sudo apt update
安裝Docker引擎:
sudo apt install docker-ce docker-ce-cli containerd.io
驗證Docker是否成功安裝:
sudo docker run hello-world
方法二:通過腳本一鍵安裝
下載Docker安裝腳本:
curl -fsSL https://get.docker.com -o get-docker.sh
運行腳本進行安裝:
sudo sh get-docker.sh
驗證Docker是否成功安裝:
sudo docker run hello-world
注意:在安裝Docker之前,請確保您的系統滿足最低要求,并且當前用戶具有sudo權限。