English | Tiếng Việt
This repository contains Docker files to run LCOJ.
Based on dmoj-docker.
You need to install Docker and Docker Compose before getting started.
git clone --recursive https://github.com/luyencode/lcoj-docker.git
cd lcoj-docker/dmojFrom now on, all commands should be run in the dmoj directory.
Run the initialization script to create necessary directories:
./scripts/initializeCreate configuration files from examples:
cp environment/mysql-admin.env.example environment/mysql-admin.env
cp environment/mysql.env.example environment/mysql.env
cp environment/site.env.example environment/site.envThen edit these files:
- Set MySQL passwords in
mysql.envandmysql-admin.env - Set host and secret key in
site.env - Configure
server_nameindmoj/nginx/conf.d/nginx.conf
docker compose builddocker compose up -d site db redis celery./scripts/migrate./scripts/copy_static./scripts/manage.py loaddata navbar
./scripts/manage.py loaddata language_small
./scripts/manage.py loaddata demoNote: The commands above create an admin account with both username and password set to admin. You should change the password or remove this account.
Or create your own superuser account:
./scripts/manage.py createsuperuserStart all services:
docker compose up -dStop all services:
docker compose downThe judge server is not included in this Docker setup. Please refer to Setting up a Judge.
The bridge instance is included and will run automatically when you start the services.
When updating the system, you may need to run migrations:
./scripts/migrateIf static files change, you need to rebuild them:
./scripts/copy_staticDepending on what changed, you need to rebuild or restart:
If dependencies changed:
docker compose up -d --build base site celery bridged wseventIf only code changed:
docker compose restart site celery bridged wseventIf you already have Nginx running on your host machine, you can change the port in docker-compose.yml and configure a proxy pass.
Example Nginx configuration on host machine:
server {
listen 80;
listen [::]:80;
add_header X-UA-Compatible "IE=Edge,chrome=1";
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
location / {
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:10080/;
}
}In this case, you need to change the port in the Docker container to 10080.
By default, all services run on the same machine. To handle more users, you can distribute services across multiple servers:
- Central server: nginx, db, redis, bridged, wsevent
- Workers: nginx, site, celery
Edit dmoj/nginx/conf.d/nginx.conf to distribute traffic to workers. Refer to Nginx docs.
Example configuration:
upstream site {
ip_hash;
server srv1.example.com;
server srv2.example.com;
server srv3.example.com;
}
server {
listen 80;
listen [::]:80;
location / {
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://site/;
}
location /event/ {
proxy_pass http://wsevent:15100/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
location /channels/ {
proxy_read_timeout 120;
proxy_pass http://wsevent:15102/;
}
}Open these ports in dmoj/docker-compose.yml:
- db: 3306
- redis: 6379
- bridged: 9998, 9999
- wsevent: 15100, 15101, 15102
Start services:
docker compose up -d nginx db redis bridged wseventEdit dmoj/environment/site.env and dmoj/environment/mysql.env to point to the central server.
Start services:
docker compose up -d nginx site celerySee full documentation at: https://docs.luyencode.net
If you encounter any issues:
- Create an issue at GitHub Issues
- If you need help with installation, LCOJ offers free installation support: https://luyencode.net/about/#lien-he