Skip to content

Run the API with Docker Compose

api/docker-compose.dev.yml runs the API in a container, with your code and your plugins mounted for live reload. Only the Django server runs in the container: Vault, Redis and the Celery workers keep running on your machine, as in the development setup, and the container reaches them through host.docker.internal.

  • Docker, with Docker Compose.
  • An api/.env file, created as described in Configure the API.
  • Vault and Redis running on your machine (pixi run vault, pixi run redis).

The build context is the folder that holds madbot/, so that the image can include your plugins. By default, it takes them from a madbot-plugins/ folder next to madbot/:

.
├── madbot/
│ ├── api/
│ └── client/
└── madbot-plugins/
├── madbot_ena_plugin/
└── …

To use another folder, set MADBOT_PLUGINS_DIR before you start the stack. The path is relative to the folder that holds madbot/:

Terminal window
export MADBOT_PLUGINS_DIR=my-plugins

From api/:

Terminal window
# First run, or after a change to the Dockerfile or the dependencies
docker compose -f docker-compose.dev.yml up --build
# Next runs
docker compose -f docker-compose.dev.yml up

The API answers on port 8000. Add -d to run the container in the background, then follow its logs:

Terminal window
docker compose -f docker-compose.dev.yml up -d
docker compose -f docker-compose.dev.yml logs -f

Stop and remove the container:

Terminal window
docker compose -f docker-compose.dev.yml down

The workers run on your machine. Point them to the Redis of your machine, then start them from api/:

Terminal window
export REDIS_HOST=localhost
export CELERY_BROKER_URL=redis://localhost:6379/0
export CELERY_RESULT_BACKEND=redis://localhost:6379/1
pixi run madbot celery

The Compose file sets these variables for the container, on top of api/.env:

VariableValue
REDIS_HOSThost.docker.internal
DB_HOSThost.docker.internal
MADBOT_VAULT_URLhttp://host.docker.internal:8200
CELERY_BROKER_URLredis://host.docker.internal:6379/0
CELERY_RESULT_BACKENDredis://host.docker.internal:6379/1

The container has no CPU, memory or disk limit, so that live reload and the mounted plugins work freely. To limit it on a small machine, uncomment the lines of docker-compose.dev.yml:

mem_limit: 2g # at most 2 GB of memory
cpus: 1.5 # at most 1.5 CPU cores
driver_opts:
type: tmpfs
device: tmpfs
o: size=5G # at most 5 GB for /app/data
SymptomCheck
The container does not startPort 8000 is free.
Errors about Vault or RedisThey run on your machine, and host.docker.internal resolves from the container.
Missing settingsapi/.env holds them, next to docker-compose.dev.yml.

To look inside the container, run a shell in it:

Terminal window
docker compose -f docker-compose.dev.yml run --rm madbot /bin/bash

To free disk space, remove the unused containers, networks, images and build cache:

Terminal window
docker system prune -a --volumes