Deploy a backend worker service
Run a non-HTTP background service (worker, queue consumer, cron) with Docker and cron.

What you'll run
A long-running background service (worker, queue consumer, or scheduled job) that does not need a public port. Docker-in-Docker is available on the instance for isolation.
Option A -- background worker
bash
$ docker run -d \
--name worker \
--restart unless-stopped \
-e REDIS_URL=redis://redis:6379 \
-e DATABASE_URL=postgresql://user:pass@db:5432/app \
ghcr.io/yourorg/your-worker:latest
Option B -- compose with dependencies
yaml
services:
worker:
image: ghcr.io/yourorg/your-worker:latest
restart: unless-stopped
depends_on: [redis, db]
environment: { REDIS_URL: "redis://redis:6379", DATABASE_URL: "postgresql://user:pass@db:5432/app" }
redis:
image: redis:7-alpine
db:
image: postgres:16-alpine
volumes: ["pg_data:/var/lib/postgresql/data"]
environment: { POSTGRES_DB: app, POSTGRES_USER: user, POSTGRES_PASSWORD: pass }
volumes: { pg_data: {} }
bash
$ docker compose up -d
Scheduled tasks (cron)
bash
$ # Run a one-off migration
$ docker exec worker python manage.py migrate
$ # Add a cron job
$ crontab -e
0 * * * * docker exec worker python manage.py cleanup
Verify
bash
$ docker ps
$ docker logs -f worker
Practical -- try it now
Your worker in 5 minutes
- Provision an instance and SSH in.
- Deploy your worker with docker compose up -d.
- Check logs with docker logs -f worker.
Ask a question...
Ctrl+I