Files
decomp.me/docs/DOCKER.md
Mark Street 77bc4e6672 Add Docker Production setup (#1580)
* Add Docker Production setup

* Fixup ci

* forgot to hit save..

* try again

* More trying

* tweaks

* 🐻 hide all the dumbness

* overriding INTERNAL_API_BASE is optional

* Add pgdump dir to allow pg_restore

* rework nginx configuration for prod

* Add proxy timeouts for sanity
2025-06-07 15:51:39 +01:00

3.2 KiB

Docker

Prerequisites:

Docker

You will need Docker and Docker Compose. Follow the instructions for your distro.

Production

  1. Create a docker.prod.env and set the necessary configuration options (see .env for inspiration).
nano docker.prod.env
  1. Bring up postgres & nginx containers
docker compose -f docker-compose.prod.yaml up -d postgres nginx
  1. Build and bring up backend
docker compose -f docker-compose.prod.yaml build backend
docker compose -f docker-compose.prod.yaml up -d backend
  1. Build and bring up frontend (relies on backend for SSR)
# NOTE: this can be overridden if needed, i.e. --build-arg INTERNAL_API_BASE=https://decomp.me/api
docker compose -f docker-compose.prod.yaml build frontend
docker compose -f docker-compose.prod.yaml up -d frontend

SSL Certificates Bootstrap

In order to bring up nginx we need to have SSL certificates. In order to do that we need to get nginx to run only on port 80, then run certbot to fetch the certs.

  1. Modify the nginx/production.conf to comment out the whole server { listen 443 ssl http2; ... } block.

  2. Bring up nginx

docker compose -f docker-compose.prod.yaml up -d nginx
  1. Run certbot:
docker compose run --rm certbot certonly \
  --webroot -w /var/www/certbot \
  -d decomp.me -d www.decomp.me \
  --email you@your-email.com \
  --agree-tos \
  --no-eff-email
  1. Uncomment the 443 block and then send a reload trigger to nginx
docker compose exec nginx nginx -t # sanity check configuration OK
docker compose exec nginx nginx -s reload

Development

There is a docker-compose.yaml file to help you spin up a dev instance quickly.

Run in foreground:

docker compose up --build

The processes will run in the foreground until you CTRL+C to trigger a shutdown.

Navigate to http://localhost:80 in your browser.

Run daemonised:

docker compose up -d && docker compose logs -f

You can CTRL+C to stop tailing logs. If you want to stop the processes then running docker compose down will shut everything down.

Note: The first time you bring up the containers can take a minute or so - Docker has to pull/build images, grab Node dependencies, apply database migrations etc. Subsequent runs will be significantly faster to spin up.

Configuration

By default, the Docker backend container is configured with the Switch platform disabled (due to the size of the Clang compilers).

Platforms can be enabled by changing the ENABLE_<PLATFORM>_SUPPORT variables to YES in the docker-compose.yaml and re-running the docker compose up command.

E.g. to enable SWITCH platform:

  backend:
    build:
      context: backend
    environment:
      - ENABLE_SWITCH_SUPPORT=YES

Connecting from a different host

If you wish to run decomp.me on one machine and connect from a different one (e.g. to test the site on your phone) please edit ./backend/docker.dev.env to add your hostname to the ALLOWED_HOSTS environment variable.

E.g. if your hostname is mylaptop:

ALLOWED_HOSTS="backend,localhost,127.0.0.1,mylaptop"