Skip to content

Getting started with docker compose

Here we'll get you set up with a basic docker compose setup.

You'll need to do some more work if you want to turn it into a production setup, but it's enough to try out Karrot, or use as a base for your own setup.

What is included?

With this setup you'll have running:

  • nginx serving up the static files - using our frontend docker image
  • python app server running the backend - using our backend docker image
  • python background worker - uses the same image as the app server
  • PostgreSQL - using the standard library image
  • Redis - using the standard library image

What is not included?

You won't get:

  • secret handling
  • backups
  • geoip
  • TLS certificates

If you want that stuff, consider the Co-op Cloud option, otherwise you'll have to configure those things yourself.

Steps

1. Prerequisites

  • you have docker set up and running
  • you have docker compose tooling available
  • you have created a directory to work in

2. Get the docker-compose.yml

Obtain it via wget

shell
wget https://docs.karrot.world/self-host/docker-compose.yml

... or copy and paste from here

yaml
services:
  web:
    image: "codeberg.org/karrot/karrot-frontend:latest"
    environment:
      LISTEN: "8080"
    healthcheck:
      test: ["CMD", "curl", "-f", "localhost:8080"]
    ports:
      - "8080:8080"
    volumes:
      - "app_data:/app/uploads"

  app: &app
    image: "codeberg.org/karrot/karrot-backend:latest"
    volumes:
      - "app_data:/app/uploads"
    depends_on:
      - redis
      - db
    command: server
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/api/healthcheck/"]
    environment: &app_environment
      MODE: "prod"
      LISTEN_HOST: '0.0.0.0'
      SITE_URL: "http://localhost:8080"
      FILE_UPLOAD_USE_ACCEL_REDIRECT: "true"
      SECRET_KEY: "not-very-secret"
      DATABASE_HOST: "db"
      DATABASE_PORT: "5432"
      DATABASE_NAME: "karrot"
      DATABASE_USER: "karrot"
      DATABASE_PASSWORD: "not-a-proper-password"
      REDIS_HOST: "redis"
      MIGRATE: yes

  worker:
    <<: *app
    depends_on:
      - app
    command: worker
    healthcheck:
      disable: true
    environment:
      <<: *app_environment
      MIGRATE: no

  redis:
    image: "redis:6-alpine"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
    volumes:
      - "redis_data:/data"

  db:
    image: "postgres:14-alpine"
    volumes:
      - "postgres_data:/var/lib/postgresql/data"
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "karrot"]
    environment:
      POSTGRES_USER: "karrot"
      POSTGRES_DB: "karrot"
      POSTGRES_PASSWORD: "not-a-proper-password"

volumes:
  app_data:
  postgres_data:
  redis_data:

3. Start it up!

shell
docker compose up -d

When it's running you should be able to visit localhost:8080.

4. Create some sample data (optional)

If you want to see a more populated instance you can run this to create some fake data:

shell
docker compose exec app ./manage.py create_sample_data

You can then login as foo@foo.com / foofoo. All the other created users have their passwords set to 123.