> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/on-premises/zh-tw/ru-men-zhi-nan/requirements/setup-docker.md).

# 設定 Docker

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

* Docker Engine（Docker CE）
* Docker Compose **外掛程式** (`docker compose`, v2）

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

{% hint style="warning" %}
避免安裝 `docker.io` 從 Ubuntu 的預設 apt 儲存庫。\
請使用 Docker 的官方儲存庫，以取得較新的 Docker 版本以及 `docker compose` 外掛程式。
{% endhint %}

官方文件來源： <https://docs.docker.com/engine/install/ubuntu/>.

{% stepper %}
{% step %}

### 1）移除舊的／衝突的套件（如果有）

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

{% code overflow="wrap" %}

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

{% endcode %}

即使某些套件未安裝，此命令也很安全。
{% endstep %}

{% step %}

### 2）新增 Docker 的官方 apt 儲存庫

安裝必要條件：

```bash
sudo apt update
sudo apt install -y ca-certificates curl
```

新增 Docker GPG 金鑰：

{% code overflow="wrap" %}

```bash
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
```

{% endcode %}

新增儲存庫：

{% code overflow="wrap" %}

```bash
# 將儲存庫加入 Apt 來源：
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
類型：deb
URI：https://download.docker.com/linux/ubuntu
套件系列：$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
元件：stable
簽署者：/etc/apt/keyrings/docker.asc
EOF

sudo apt update
```

{% endcode %}
{% endstep %}

{% step %}

### 3）安裝 Docker Engine + Compose 外掛程式

安裝 Docker 與 Compose 外掛程式：

{% code overflow="wrap" %}

```bash
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

{% endcode %}

開機時啟動 Docker：

```bash
sudo systemctl enable --now docker
```

{% endstep %}

{% step %}

### 4）驗證安裝

這些命令應可正常執行且不會出錯：

```bash
docker --version
docker compose version
sudo docker run --rm hello-world
docker ps
```

{% endstep %}

{% step %}

### 5）（可選）不使用 sudo 執行 Docker

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

```bash
sudo usermod -aG docker $USER
```

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

```bash
newgrp docker
```

現在這應該可以在不使用 `sudo`:

```bash
docker ps
```

{% hint style="danger" %}
此 `docker` 群組在主機上擁有與 root 等同的存取權限。\
這是典型 Overleaf 安裝的預期行為，若您啟用沙箱化編譯，則尤其相關。
{% endhint %}
{% endstep %}
{% endstepper %}

### 下一步

一旦 Docker 可正常運作，請繼續進行 Toolkit 安裝步驟，詳見 [使用 Toolkit](/on-premises/zh-tw/an-zhuang/using-the-toolkit.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/on-premises/zh-tw/ru-men-zhi-nan/requirements/setup-docker.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
