> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 0. 設定 Docker

> 在 Ubuntu 上安裝 Docker Engine 與 Compose 外掛，以部署 Overleaf。

Overleaf 在 Docker 上執行。您必須安裝：

* Docker Engine（Docker CE）
* Docker Compose 外掛（`docker compose`，v2）

這些步驟適用於較新的 Ubuntu LTS（20.04/22.04/24.04）。

> [!WARNING]
>
> 請避免從 Ubuntu 預設的 apt 儲存庫安裝 `docker.io`。\
> 請使用 Docker 官方儲存庫，以取得較新的 Docker 版本以及 `docker compose` 外掛。

官方文件來源：[https://docs.docker.com/engine/install/ubuntu/](https://docs.docker.com/engine/install/ubuntu/)。

**1. 1) 移除舊的或衝突的套件（若存在）**

如果先前曾從其他來源安裝 Docker，請先將其移除：

```bash wrap theme={null}
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1)
```

即使部分套件未安裝，此指令也可安全執行。

**2. 2) 新增 Docker 官方 apt 儲存庫**

安裝必要套件：

```bash theme={null}
sudo apt update
sudo apt install -y ca-certificates curl
```

新增 Docker GPG 金鑰：

```bash wrap theme={null}
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
```

新增儲存庫：

```bash wrap theme={null}
# Add the repository to Apt sources:
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update
```

**3. 3) 安裝 Docker Engine 與 Compose 外掛**

安裝 Docker 與 Compose 外掛：

```bash wrap theme={null}
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

設定 Docker 開機時自動啟動：

```bash theme={null}
sudo systemctl enable --now docker
```

**4. 4) 驗證安裝**

以下指令應能正常執行且沒有錯誤：

```bash theme={null}
docker --version
docker compose version
sudo docker run --rm hello-world
docker ps
```

**5. 5)（選用）不使用 sudo 執行 Docker**

將您的使用者加入 `docker` 群組：

```bash theme={null}
sudo usermod -aG docker $USER
```

接著**登出後再重新登入**，或執行：

```bash theme={null}
newgrp docker
```

現在以下指令應該不需要 `sudo` 也能執行：

```bash theme={null}
docker ps
```

> [!CAUTION]
>
> `docker` 群組在主機上擁有等同 root 的存取權限。\
> 這在一般的 Overleaf 安裝中是預期的情況，若您啟用了 Sandboxed Compiles，這一點尤其重要。

### 下一步

Docker 正常運作後，請繼續進行 [1. 下載 Toolkit](https://ayakaleaf-pro.mintlify.site/zh-TW/on-premises/installation/using-the-toolkit/1.-download-the-toolkit.md)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.