Self Hosting

Deploying Directus

This section covers the deployment process of Directus, including environment variables, versioning, persistence, and initial admin user setup.

Directus is provided as a Docker image. This means you can deploy it on many different platforms. While each is slightly different, the core concepts are the same.

See all vendor-specifc self-hosting deployment tutorials.

Environment Variables

Directus uses environment variables for database and asset storage connection details and some key project configuration. At the very least, you will need to configure a database and set a SECRET.

Dependent on your hosting provider, you will need to set these variables in a different place. In some, it is a dedicated key/value store provided in a Web UI. In others, it is a file that is loaded when the Docker container starts. As Directus is provided as a Docker image, you shouldn't need to do more than set environment variables to get started.

Version Pinning

The Docker image is published on Docker Hub as directus/directus. The version is specified in the tag. For example, directus/directus:11.1.1. You can always use the latest tag instead of an explicit version, but we recommend pinning to a specific version for production environments.

This also means your project will not be automatically updated to the latest version when restarting the container, which is recommended in case of required changes or breaking changes.

Persistence

Docker containers are ephemeral by design. This means that any changes you make while the container is running will be lost when the container is stopped or restarted.

To persist data, you will need to mount a volume to the container. When using Docker Compose, this is done by adding a volumes section to the docker-compose.yml file, which you can see in our create a project page.

Files can be persisted by mounting a volume to the container, or by setting up an external storage location.

Initial Admin User

You do not need to create the initial admin user in the database manually. When the container starts, you will see a message in the terminal that includes the email address and password for the initial user.

You can manually set an email address, password, and static access token for the initial admin user using the ADMIN_* environment variables.

Docker Compose Examples

Postgres, Redis, Directus, Local Files Be sure to replace placeholder values with your own.
services:
  database:
    image: postgis/postgis:13-master
    volumes:
      - ./data/database:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: "directus"
      POSTGRES_PASSWORD: "directus"
      POSTGRES_DB: "directus"
    healthcheck:
      test: ["CMD", "pg_isready", "--host=localhost", "--username=directus"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_interval: 5s
      start_period: 30s

  cache:
    image: redis:6
    healthcheck:
      test: ["CMD-SHELL", "[ $$(redis-cli ping) = 'PONG' ]"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_interval: 5s
      start_period: 30s

  directus:
    image: directus/directus:REPLACE_WITH_VERSION
    ports:
      - 8055:8055
    volumes:
      - ./uploads:/directus/uploads
      - ./extensions:/directus/extensions
    depends_on:
      database:
        condition: service_healthy
      cache:
        condition: service_healthy
    environment:
      SECRET: "REPLACE_WITH_YOUR_SECRET"

      DB_CLIENT: "pg"
      DB_HOST: "database"
      DB_PORT: "5432"
      DB_DATABASE: "directus"
      DB_USER: "directus"
      DB_PASSWORD: "directus"

      CACHE_ENABLED: "true"
      CACHE_AUTO_PURGE: "true"
      CACHE_STORE: "redis"
      REDIS: "redis://cache:6379"

      ADMIN_EMAIL: "REPLACE_WITH_YOUR_EMAIL"
      ADMIN_PASSWORD: "REPLACE_WITH_YOUR_PASSWORD"

      PUBLIC_URL: "REPLACE_WITH_YOUR_URL"
Request Other Examples We're keeping this section light for now, but if you need examples for other database providers, let us know!