使用Docker部署DomJudge
首先要在/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
中。需要迁移时只需要迁移这个文件夹即可。
看看其他吧