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.
Before you start
Section titled “Before you start”- Docker, with Docker Compose.
- An
api/.envfile, created as described in Configure the API. - Vault and Redis running on your machine (
pixi run vault,pixi run redis).
Where the plugins come from
Section titled “Where the plugins come from”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/:
export MADBOT_PLUGINS_DIR=my-pluginsStart the API
Section titled “Start the API”From api/:
# First run, or after a change to the Dockerfile or the dependenciesdocker compose -f docker-compose.dev.yml up --build
# Next runsdocker compose -f docker-compose.dev.yml upThe API answers on port 8000. Add -d to run the container in the background, then follow its logs:
docker compose -f docker-compose.dev.yml up -ddocker compose -f docker-compose.dev.yml logs -fStop and remove the container:
docker compose -f docker-compose.dev.yml downStart the Celery workers
Section titled “Start the Celery workers”The workers run on your machine. Point them to the Redis of your machine, then start them from api/:
export REDIS_HOST=localhostexport CELERY_BROKER_URL=redis://localhost:6379/0export CELERY_RESULT_BACKEND=redis://localhost:6379/1pixi run madbot celerySettings set by the stack
Section titled “Settings set by the stack”The Compose file sets these variables for the container, on top of api/.env:
| Variable | Value |
|---|---|
REDIS_HOST | host.docker.internal |
DB_HOST | host.docker.internal |
MADBOT_VAULT_URL | http://host.docker.internal:8200 |
CELERY_BROKER_URL | redis://host.docker.internal:6379/0 |
CELERY_RESULT_BACKEND | redis://host.docker.internal:6379/1 |
Limit the resources
Section titled “Limit the resources”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 memorycpus: 1.5 # at most 1.5 CPU coresdriver_opts: type: tmpfs device: tmpfs o: size=5G # at most 5 GB for /app/dataTroubleshooting
Section titled “Troubleshooting”| Symptom | Check |
|---|---|
| The container does not start | Port 8000 is free. |
| Errors about Vault or Redis | They run on your machine, and host.docker.internal resolves from the container. |
| Missing settings | api/.env holds them, next to docker-compose.dev.yml. |
To look inside the container, run a shell in it:
docker compose -f docker-compose.dev.yml run --rm madbot /bin/bashTo free disk space, remove the unused containers, networks, images and build cache:
docker system prune -a --volumes
