This note details the steps I took to self-host Judge0 on a Hetzner cloud instance.

I setup the cloud instance as follows:

  • Location: Helsinki as Falkenstein and Nuremberg had no cost optimised option available at the time. I wanted the CX33 option.
  • OS: Ubuntu 22.04 LTS as suggested by judge0 docs.
  • CPU: 4 vCPU
  • RAM: 8 GB
  • Disk: 80 GB SSD
  • Price: $8.99 per month.

Step 0: Connect to the Server

ssh root@YOUR_SERVER_IP

1. Update Ubuntu and GRUB

Update Ubuntu

sudo apt update
sudo apt upgrade -y

Update GRUB

Open file /etc/default/grub

sudo nano /etc/default/grub

Then, add systemd.unified_cgroup_hierarchy=0 in the value of GRUB_CMDLINE_LINUX variable.

Apply the changes: sudo update-grub

Restart your server: sudo reboot

Then to double check,

ssh root@YOUR_SERVER_IP
stat -fc %T /sys/fs/cgroup/

You should see see tmpfs.

2. Create a non-root user

adduser judge0

Add it to sudo:

usermod -aG sudo judge0

Copy your SSH key:

rsync --archive --chown=judge0:judge0 ~/.ssh /home/judge0

After creating the non-root user and copying your SSH key, you can safely close the current root SSH session.

exit

Now reconnect:

ssh judge0@YOUR_SERVER_IP

3. Install Docker

First, let’s update:

sudo apt update

Now install Docker:

sudo apt install -y docker.io docker-compose-v2

Enable Docker:

sudo systemctl enable docker
sudo systemctl start docker

Allow your user to run Docker:

sudo usermod -aG docker $USER

Log out and back in.

Verify:

docker --version
docker compose version

4. Get Judge0

Git route

If using the Git route check if you have Git:

git --version

If not then run,

sudo apt install git -y

wget route (took this route)

This is the suggested approach according to the judge0 docs

First install unzip:

sudo apt install unzip

Then use wget to get the archive containing the judge0 source files:

wget https://github.com/judge0/judge0/releases/download/v1.13.1/judge0-v1.13.1.zip

Decompress the archive:

unzip judge0-v1.13.1.zip

5. Configure environment

I used the wget route so get my Judge0 CE v1.13.1 instance running.

Configure the Redis Password

I generated a password using random.org and then opened the judge0.conf file.

cd judge0-v1.13.1
vim judge0.conf

Then I set REDIS_PASSWORD= to the generated password and saved the changes to the file.

Configure the Postgress Password

Ensure you are in the judge0-v1.13.1 directory

vim judge0.conf

Then I set POSTGRES_PASSWORD to the generated password and saved the changes to the file.

Setup the Docker Jazz

I ran the following commands to complete the Docker setup:

docker-compose up -d db redis
sleep 10s
docker-compose up -d
sleep 5s

So something went wrong…

When I navigated to http://<IP ADDRESS OF YOUR SERVER>:2358/docs I didn’t get anything.

So I ran,

docker ps

To check my active containers and only saw to:

CONTAINER ID   IMAGE           COMMAND                  CREATED              STATUS              PORTS      NAMES
42b232c3c8d6   postgres:16.2   "docker-entrypoint.s…"   About a minute ago   Up About a minute   5432/tcp   judge0-v1131-db-1
9b5edfee2eb7   redis:7.2.4     "docker-entrypoint.s…"   About a minute ago   Up About a minute   6379/tcp   judge0-v1131-redis-1

Even tried docker ps -a and got the same output.

This command docker logs judge0-server just produced an error so I ran:

docker compose down
docker compose up -d

And it worked!

And it worked!

Next,

Linking self-hosted Judge0 to a fastapi server