Skip to content

Commit 62889e1

Browse files
Kevinjilvmcj
authored andcommitted
Add instructions for setting up Traefik in Docker
Include an example which sets up a Traefik reverse proxy in Docker, including ACME for automated https certificate management. The deprecated and legacy `--link` flag of run commands is replaced with Docker networks in all run commands.
1 parent 427e087 commit 62889e1

File tree

3 files changed

+101
-4
lines changed

3 files changed

+101
-4
lines changed

docker/README.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,43 @@ These containers do not include MySQL / MariaDB; the [MariaDB](https://hub.docke
3333

3434
These images are available on the [Docker Hub](https://hub.docker.com) as `domjudge/domserver` and `domjudge/judgehost`.
3535

36+
### DOMjudge network
37+
For isolation, create a Docker network which will be used for the communication between DOMjudge-related containers.
38+
```bash
39+
docker network create dj
40+
```
41+
42+
### Traefik container (Optional)
43+
An easy way to get trusted certificates using ACME is running the Traefik reverse proxy in front of the DOMjudge stack. Create a Docker network which allows communication across compose stacks using:
44+
45+
```bash
46+
docker network create proxy_network
47+
```
48+
49+
Now, you can deploy a Traefik reverse proxy. An example test deployment with **insecure** API access on port `8080` can be created using:
50+
51+
```bash
52+
docker run --name traefik --net proxy_network -p 80:80 -p 443:443 -p 8080:8080 -v /letsencrypt -v /var/run/docker.sock:/var/run/docker.sock:ro traefik:v2.10 \
53+
--api.insecure=true \
54+
--providers.docker=true \
55+
--providers.docker.exposedbydefault=false \
56+
--entrypoints.web.address=:80 \
57+
--entrypoints.websecure.address=:443 \
58+
--certificatesresolvers.myresolver.acme.email=your-email@example.com \
59+
--certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web \
60+
--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
61+
```
62+
63+
This will start a Traefik container listening for http traffic on port `80`, https traffic on port `443`, and listening for Traefik dashboard traffic at port `8080`.
64+
Traefik automatically listens to the Docker socket for running containers with labels defining reverse proxy routes.
65+
It also defines an ACME resolver named `myresolver` which creates a Let's Encrypt ACME account using email address `[email protected]` used to create the TLS certificates for https traffic.
66+
3667
### MariaDB container
3768

3869
Before starting the containers, make sure you have a MySQL / MariaDB database somewhere. The easiest way to get one up and running is to use the [MariaDB](https://hub.docker.com/r/_/mariadb/) Docker container:
3970

4071
```bash
41-
docker run -it --name dj-mariadb -e MYSQL_ROOT_PASSWORD=rootpw -e MYSQL_USER=domjudge -e MYSQL_PASSWORD=djpw -e MYSQL_DATABASE=domjudge -p 13306:3306 mariadb --max-connections=1000
72+
docker run -it --name dj-mariadb --net dj -e MYSQL_ROOT_PASSWORD=rootpw -e MYSQL_USER=domjudge -e MYSQL_PASSWORD=djpw -e MYSQL_DATABASE=domjudge -p 13306:3306 mariadb --max-connections=1000
4273
```
4374

4475
This will start a MariaDB container, set the root password to `rootpw`, create a MySQL user named `domjudge` with password `djpw` and create an empty database named `domjudge`. It will also expose the server on port `13306` on your local machine, so you can use your favorite MySQL GUI to connect to it. If you want to save the MySQL data after removing the container, please read the [MariaDB](https://hub.docker.com/r/_/mariadb/) Docker Hub page for more information.
@@ -47,10 +78,10 @@ This will start a MariaDB container, set the root password to `rootpw`, create a
4778

4879
Next, if you are on Linux make sure you have cgroups enabled. See the [DOMjudge documentation about setting up a judgehost](https://www.domjudge.org/docs/manual/master/install-judgehost.html#linux-control-groups) for information about how to do this. Docker on Windows and macOS actually use a small Linux VM which already has these options set.
4980

50-
Now you can run the domserver using the following command:
81+
Without the optional Traefik reverse proxy, you can run the domserver using the following command:
5182

5283
```bash
53-
docker run --link dj-mariadb:mariadb -it -e MYSQL_HOST=mariadb -e MYSQL_USER=domjudge -e MYSQL_DATABASE=domjudge -e MYSQL_PASSWORD=djpw -e MYSQL_ROOT_PASSWORD=rootpw -p 12345:80 --name domserver domjudge/domserver:latest
84+
docker run -it --name domserver --net dj -e MYSQL_HOST=dj-mariadb -e MYSQL_USER=domjudge -e MYSQL_DATABASE=domjudge -e MYSQL_PASSWORD=djpw -e MYSQL_ROOT_PASSWORD=rootpw -p 12345:80 domjudge/domserver:latest
5485
```
5586

5687
If you want a specific DOMjudge version instead of the latest, replace `latest` with the DOMjudge version (e.g. `5.3.0`).
@@ -70,6 +101,26 @@ If you lose access to the admin user, see the [DOMjudge documentation on resetti
70101

71102
Make a note of the password for the `judgehost` user, it will be used when the judgehost container is configured. The password can be changed from the web interface by editing the `judgehost` user.
72103

104+
For a deployment using the Traefik container with ACME on domain `domjudge.example.com`, run domserver using the following command:
105+
106+
```bash
107+
docker create -it --name domserver --net dj -e MYSQL_HOST=dj-mariadb -e MYSQL_USER=domjudge -e MYSQL_DATABASE=domjudge -e MYSQL_PASSWORD=djpw -e MYSQL_ROOT_PASSWORD=rootpw \
108+
-l "traefik.enable=true" \
109+
-l "traefik.http.services.domjudge.loadbalancer.server.port=80" \
110+
-l "traefik.http.routers.domjudge.rule=Host(\`domjudge.example.com\`)" \
111+
-l "traefik.http.routers.domjudge.entrypoints=web" \
112+
-l "traefik.http.routers.domjudgesecure.rule=Host(\`domjudge.example.com\`)" \
113+
-l "traefik.http.routers.domjudgesecure.entrypoints=websecure" \
114+
-l "traefik.http.routers.domjudgesecure.tls=true" \
115+
-l "traefik.http.routers.domjudgesecure.tls.certresolver=myresolver" \
116+
-l "traefik.docker.network=proxy_network" \
117+
domjudge/domserver:latest
118+
docker network connect proxy_network domserver
119+
docker start -a domserver
120+
```
121+
122+
With DNS configured, you can now access the web interface on [http://domjudge.example.com/](http://domjudge.example.com/) or [https://domjudge.example.com/](https://domjudge.example.com/) and log in as admin.
123+
73124
#### Environment variables
74125

75126
The following environment variables are supported by the `domserver` container:
@@ -130,13 +181,14 @@ where `[service]` is one of `nginx` or `php`.
130181

131182
#### Docker-compose
132183
See https://github.com/DOMjudge/domjudge-packaging/blob/main/docker/docker-compose.yml for a docker-compose example which automates the steps above.
184+
When using the optional Traefik reverse proxy, deploy the stack defined in https://github.com/DOMjudge/domjudge-packaging/blob/main/docker/docker-compose-traefik.yml first and uncomment the relevant lines in the `docker-compose.yml` file.
133185

134186
### Judgehost container
135187

136188
To run a single judgehost, run the following command:
137189

138190
```bash
139-
docker run -it --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro --name judgehost-0 --link domserver:domserver --hostname judgedaemon-0 -e DAEMON_ID=0 domjudge/judgehost:latest
191+
docker run -it --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro --name judgehost-0 --net dj --hostname judgedaemon-0 -e DAEMON_ID=0 domjudge/judgehost:latest
140192
```
141193

142194
Again, replace `latest` with a specific version if desired. Make sure the version matches the version of the domserver.

docker/docker-compose-traefik.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3'
2+
3+
services:
4+
traefik:
5+
image: "traefik:v2.10"
6+
container_name: "traefik"
7+
command:
8+
- --api.insecure=true
9+
- --providers.docker=true
10+
- --providers.docker.exposedbydefault=false
11+
- --entrypoints.web.address=:80
12+
- --entrypoints.websecure.address=:443
13+
- --certificatesresolvers.myresolver.acme.email=your-email@example.com
14+
- --certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web
15+
- --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
16+
ports:
17+
- "80:80"
18+
- "443:443"
19+
- "8080:8080"
20+
volumes:
21+
- /letsencrypt
22+
- /var/run/docker.sock:/var/run/docker.sock:ro
23+
networks:
24+
- proxy_network
25+
26+
networks:
27+
proxy_network:
28+
external: true

docker/docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,20 @@ services:
2525
- MYSQL_HOST=mariadb
2626
ports:
2727
- 12345:80
28+
# When using the Traefik reverse proxy container, uncomment the lines below.
29+
# labels:
30+
# - traefik.enable=true
31+
# - traefik.http.services.domjudge.loadbalancer.server.port=80
32+
# - traefik.http.routers.domjudge.rule=Host(`domjudge.example.com`)
33+
# - traefik.http.routers.domjudge.entrypoints=web
34+
# - traefik.http.routers.domjudgesecure.rule=Host(`domjudge.example.com`)
35+
# - traefik.http.routers.domjudgesecure.entrypoints=websecure
36+
# - traefik.http.routers.domjudgesecure.tls=true
37+
# - traefik.http.routers.domjudgesecure.tls.certresolver=myresolver
38+
# - traefik.docker.network=proxy_network
39+
# networks:
40+
# - default
41+
# - proxy_network
42+
# networks:
43+
# proxy_network:
44+
# external: true

0 commit comments

Comments
 (0)