1 (中文)docker
肝帝熙恩 edited this page 2025-09-07 13:59:59 +08:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Docker 设置

为了在 Docker 容器中运行 TShock您需要为以下目录设置挂载点

  • /tshockTShock 配置文件、日志和崩溃报告)
  • /worlds
  • /plugins
  • /server(可选,如果您想挂载 TShock 的工作目录)

这些文件夹可以使用 -v <主机文件夹>:<容器路径> 进行挂载

开放端口也可以使用 -p <主机端口>:<容器端口> 传递。

  • 7777 用于 Terraria
  • 7878 用于 TShock 的 REST API

例如:

# 使用 buildx 构建镜像并加载到 docker 中
docker buildx build -t tshock:latest --load .

# 运行镜像
docker run -p 7777:7777 -p 7878:7878 \
           -v /home/cider/tshock/:/tshock \
           -v /home/cider/.local/share/Terraria/Worlds:/worlds \
           -v /home/cider/tshock/plugins:/plugins \
           --rm -it tshock:latest \
           -world /worlds/backflip.wld -motd "OMFG DOCKER"

为其他平台构建

使用 docker buildx,您可以为 TShock 构建多平台镜像

例如:

# 使用 buildx 构建镜像并加载到 docker 中
docker buildx build -t tshock:linux-arm64 --platform linux/arm64 --load .

# 运行镜像
docker run -p 7777:7777 -p 7878:7878 \
           -v /home/cider/tshock/:/tshock \
           -v /home/cider/.local/share/Terraria/Worlds:/worlds \
           -v /home/cider/tshock/plugins:/plugins \
           --rm -it tshock:linux-arm64 \
           -world /worlds/backflip.wld -motd "ARM64 ftw"

使用 Docker Compose

如果您已安装 Docker Compose,您可以跳过显式构建镜像,而是使用如下的 docker-compose.yml 文件:

services:
  terraria:
    build:
      context: https://github.com/Pryaxis/TShock.git
      args:
        TARGETPLATFORM: linux/amd64
    container_name: terraria
    restart: unless-stopped
    volumes:
      - "./tshock/:/tshock"
      - "./worlds:/worlds"
      - "./plugins:/plugins"
      - "/etc/localtime:/etc/localtime:ro"
    ports:
      - "7777:7777"
      - "7878:7878" # 如果您不使用 REST 服务,可以删除此项
    command: -world /worlds/my_world.wld

要以交互方式运行服务器(例如生成世界),请使用 docker compose run --rm terraria(暂时不使用 command:)。 然后,您可以使用 docker compose up -d 在后台运行它,并让它随您的主机系统自动重启。

下载官方镜像

TShock 会为每次提交自动发布镜像。您也可以使用来自 nuget 的最新发布/发行版本。通过使用 nuget-release 标签,您实际上引用的是 TShock 的最新稳定版本。通过使用 general-devel,您实际上拥有了 TShock 的最新开发版本。我们还会自动为所有发布版本打上标签,例如 5.2.4 是一个有效的标签。