> ## 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.

# 安装 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` 插件。
</Warning>

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

<Steps>
  <Step title="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)
    ```

    即使部分软件包未安装，此命令也可以安全运行。
  </Step>

  <Step title="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
    ```
  </Step>

  <Step title="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
    ```
  </Step>

  <Step title="4) 验证安装">
    以下命令应能正常运行且不报错：

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

  <Step title="5) （可选）无需 sudo 运行 Docker">
    将你的用户添加到 `docker` 组：

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

    然后**注销并重新登录**，或运行：

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

    现在无需 `sudo` 也应能运行：

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

    <Danger>
      `docker` 组在主机上拥有等同于 root 的访问权限。\
      这对于典型的 Overleaf 安装来说是预期行为，尤其是在启用沙盒编译时更是如此。
    </Danger>
  </Step>
</Steps>

### 下一步

Docker 正常运行后，请继续执行[使用 Toolkit](/zh-CN/on-premises/installation/using-the-toolkit) 中的 Toolkit 安装步骤。


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