首先要在/etc/default/grub中的GRUB_CMDLINE_LINUX_DEFAULT内增加这一段代码:cgroup_enable=memory swapaccount=1 systemd.unified_cgroup_hierarchy=0,开启cgroup。不然判题机跑不起来。

然后将以下配置文件保存为docker-compose.yaml并对密码进行修改,其中JUDGEDAEMON_PASSWORD先留空。

version: '3.9'

networks:
  domjudge:
    name: domjudge

services:
  mariadb:
    container_name: mariadb
    image: mariadb:latest
    restart: always
    networks:
      - domjudge
    volumes:
      - ./data:/var/lib/mysql
    ports:
      - "127.0.0.1:13306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD={{root_password}}
      - MYSQL_USER=domjudge
      - MYSQL_PASSWORD={{sql_password}}
      - MYSQL_DATABASE=domjudge
    command: --max-connections=1000

  domserver:
    container_name: domserver
    image: domjudge/domserver:latest
    restart: always
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    networks:
      - domjudge
    ports:
      - "127.0.0.1:12345:80"
    depends_on:
      - mariadb
    environment:
      - CONTAINER_TIMEZONE=Asia/Shanghai
      - MYSQL_HOST=mariadb
      - MYSQL_ROOT_PASSWORD={{root_password}}
      - MYSQL_USER=domjudge
      - MYSQL_PASSWORD={{sql_password}}
      - MYSQL_DATABASE=domjudge

  judgehost-0:
    container_name: judgehost-0
    image: domjudge/judgehost:latest
    restart: always
    privileged: true
    hostname: judgedaemon-0
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    networks:
      - domjudge
    depends_on:
      - domserver
    environment:
      - CONTAINER_TIMEZONE=Asia/Shanghai
      - DAEMON_ID=0
      - JUDGEDAEMON_PASSWORD=

  judgehost-1:
    container_name: judgehost-1
    image: domjudge/judgehost:latest
    restart: always
    privileged: true
    hostname: judgedaemon-1
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    networks:
      - domjudge
    depends_on:
      - domserver
    environment:
      - CONTAINER_TIMEZONE=Asia/Shanghai
      - DAEMON_ID=1
      - JUDGEDAEMON_PASSWORD=

  judgehost-2:
    container_name: judgehost-2
    image: domjudge/judgehost:latest
    restart: always
    privileged: true
    hostname: judgedaemon-2
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    networks:
      - domjudge
    depends_on:
      - domserver
    environment:
      - CONTAINER_TIMEZONE=Asia/Shanghai
      - DAEMON_ID=2
      - JUDGEDAEMON_PASSWORD=

  judgehost-3:
    container_name: judgehost-3
    image: domjudge/judgehost:latest
    restart: always
    privileged: true
    hostname: judgedaemon-3
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    networks:
      - domjudge
    depends_on:
      - domserver
    environment:
      - CONTAINER_TIMEZONE=Asia/Shanghai
      - DAEMON_ID=3
      - JUDGEDAEMON_PASSWORD=

完成后运行docker-compose up -d

tips:如果此时报错说docker-compose版本过低,可以参考如何更新docker-compose解决。

这时候已经可以访问127.0.0.1:12345打开domjudge了。你可以修改配置以监听0.0.0.0:12345或者使用nginx反代。

运行docker exec -it domserver cat /opt/domjudge/domserver/etc/initial_admin_password.secret获取admin密码。这时候已经可以登录后台了。

这时判题机还是没启动,运行docker exec -it domserver cat /opt/domjudge/domserver/etc/restapi.secret 获取JUDGEDAEMON_PASSWORD并填入docker-compose.yaml中。再运行docker-compose up -d即可。

数据库中的数据已经进行持久化配置,在docker-compose.yaml同目录的data中。需要迁移时只需要迁移这个文件夹即可。