---
# System prepended metadata

title: Docker 安裝流程
tags: [Omniverse]

---

# Docker 安裝流程

> 2025-12-11

[TOC]

---

## 我自己看的版本

###  1. 移除舊版本
先檢查是否已安裝舊版 `docker`：
```bash
sudo apt remove docker docker-engine docker.io containerd runc -y
```
確保沒有殘留的舊版本，避免衝突。

###  2. 安裝 Docker 官方套件庫

:::danger
**注意**
Ubuntu 24.04 版本的 Docker **不應直接用 `apt install docker.io`，請使用官方 repository。**
:::

#### 🔹 2.1 更新套件索引
```bash
sudo apt update && sudo apt upgrade -y
```

#### 🔹 2.2 安裝必要的依賴
```bash
sudo apt install -y ca-certificates curl gnupg
```

#### 🔹 2.3 新增 Docker 官方 GPG 金鑰
```bash
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo tee /etc/apt/keyrings/docker.asc > /dev/null
sudo chmod a+r /etc/apt/keyrings/docker.asc
```

#### 🔹 2.4 設定 Docker 官方 Repository
```bash
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```

#### 🔹 2.5 更新套件索引
```bash
sudo apt update
```

###  3. 安裝 Docker 與 Docker Compose
執行：
```bash
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

這將會安裝：
*  `docker-ce` → Docker Engine
*  `docker-ce-cli` → Docker CLI
*  `containerd.io` → 容器運行時
*  `docker-buildx-plugin` → Docker Buildx
*  `docker-compose-plugin` → **最新的 Docker Compose (不是 docker-compose)**

###  4. 啟動與驗證 Docker

#### 🔹 4.1 啟動 Docker 並設定開機自動啟動
```bash
sudo systemctl start docker
sudo systemctl enable docker
```

#### 🔹 4.2 測試 Docker 是否安裝成功
```bash
sudo docker run hello-world
```
:::success
✅ 如果輸出 `Hello from Docker!`，表示安裝成功！🎉
:::

###  5. 設定 Docker 免 sudo（選擇性，但推薦）
預設情況下，每次執行 `docker` 都需要 `sudo`，你可以將自己加入 `docker` 群組：
> dodo 是自己名字
    
```bash
sudo usermod -aG docker dodo
```
然後登出並重新登入，或者執行：
```bash
newgrp docker
```

 測試（不需要 `sudo`）：
```bash
docker ps
```
如果沒有錯誤，表示已成功！

###  6. 測試 Docker Compose
**Docker Compose（plugin）已經包含在 `docker` 指令內，請測試：**

```bash
docker compose version
```

:::success
 輸出範例：
`Docker Compose version v2.x.x`
:::

:::info
**🎯 請注意：**
* **新版 Docker Compose (plugin)** 使用 `docker compose`（有空格）
* **舊版 `docker-compose`（沒有空格）已淘汰**，請不要用
:::

---

## NVIDIA 官方文件版本

### 安裝腳本
```bash
#Docker installation using the convenience script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

#Post-install steps for Docker
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

#Verify Docker
docker run hello-world

```

應該要跳出 `Hello from Docker!`，像這樣：

```bash
dodo@dodo-System-Product-Name:~$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/


```

### NVIDIA Container Toolkit 安裝
這邊繼續安裝：

```bash
#Configure the repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
    && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
    sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
    sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list \
    && \
    sudo apt-get update

#Install the NVIDIA Container Toolkit packages
sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker

#Configure the container runtime
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

#Verify NVIDIA Container Toolkit
docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi
```