2023年9月29日 星期五

Ubuntu 22.04安裝Docker

在Ubuntu 22.04上安裝Docker前,需要知道的事情:

  1. 安裝需要有superuser權限,一般會用sudo來達成
  2. 使用docker可以沒有superuser權限,但需要另外設定。
    若沒有設定則會出現類似下列的錯誤訊息:

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied


安裝Docker到Ubuntu 22.04的步驟有5個,依序如下:

▶︎ Step 1:安裝Docker環境需要用到的套件

sudo apt update
sudo apt install -y\
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common


▶︎ Step 2:加入Docker官方儲存庫的GPG金鑰

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

正確執行指令的輸出結果如下

/usr/share/keyrings/docker-archive-keyring.gpg: OpenPGP Public Key Version 4, Created Wed Feb 22 18:36:26 2017, RSA (Encrypt or Sign, 4096 bits); User ID; Signature; OpenPGP Certificate


▶︎ Step 3:將Docker儲存庫的位置加到apt裡面

echo "deb [arch=$(dpkg --print-architecture) 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
cat /etc/apt/sources.list.d/docker.list

輸出結果如下

deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu jammy stable


▶︎ Step 4:用apt安裝docker-ce

sudo apt install -y docker-ce
sudo systemctl status docker

輸出結果大約如下

● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-09-28 17:02:01 CST; 38s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 794972 (dockerd)
      Tasks: 45
     Memory: 29.5M
        CPU: 589ms
     CGroup: /system.slice/docker.service
             └─794972 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

▶︎ Step 5:讓一般使用者不用sudo也可以使用docker

sudo usermod -aG docker $USER

這樣就可以用一般使用者的身份來執行docker,用下列指令查看

which docker && docker --version && docker images && docker ps

會輸出docker的位置、版本、目前上面有的images與上面正在跑的containers


參考資料

_EOF_

Light Japan painting style, white snow mountains in the background, rime-frozen river, nature, ultra-clear details, cold colors, master paintings

Steps: 20, Sampler: DPM++ 2M Karras, CFG scale: 7, Seed: 2912444428, Size: 512x256, Model hash: 6ce0161689, Model: v1-5-pruned-emaonly, Version: v1.6.0-2-g4afaaf8a

Time taken: 4 min. 57.4 sec.
A: 3.35 GB, R: 3.42 GB, Sys: 2.0/2 GB (100.0%)

沒有留言:

張貼留言