• About
  • Services
  • Tech-Stack
  • Projects
  • Contact & Prices
  • Blog

Set up directus.io with Docker Compose

12.04.2024

backgroundwpfoxforms

Here’s how you can quickly and easily spin up Directus—the arguably best CMS on the market—using Docker Compose.

Why run Directus with Docker?

It’s perfect for testing Directus on your local machine and, more importantly, for installing Directus on your own Linux server.

Prerequisites

Before we begin, make sure Docker and Docker Compose are installed on your system.

Step 1: Create docker-compose.yml

Create a docker-compose.yml file inside the directus-docker folder.

docker-compose.yml

services:
  database:
    image: postgis/postgis:13-master
    # Required when running on platform other than amd64, like Apple M1/M2:
    # platform: linux/amd64
    volumes:
      - ./data/database:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: "directus"
      POSTGRES_PASSWORD: "directus"
      POSTGRES_DB: "directus"

  cache:
    image: redis:6

  directus:
    image: directus/directus:10.10.4
    ports:
      - 8055:8055
    volumes:
      - ./uploads:/directus/uploads
      # If you want to load extensions from the host
      # - ./extensions:/directus/extensions
    depends_on:
      - cache
      - database
    environment:
      KEY: "255d861b-5ea1-5996-9aa3-922530ec40b1"
      SECRET: "6116487b-cda1-52c2-b5b5-c8022c45e263"

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

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

      ADMIN_EMAIL: "[email protected]"
      ADMIN_PASSWORD: "d1r3ctu5"

      CORS_ENABLED: "true"

  adminer:
    container_name: adminer
    image: adminer
    environment:
      # ADMINER_DESIGN: ${ADMINER_DESIGN:-dracula}
      # ADMINER_DESIGN: ${ADMINER_DESIGN:-pepa-linha}
      ADMINER_DESIGN: ${ADMINER_DESIGN:-pepa-linha-dark}
    ports:
      - "8008:8080"
    depends_on:
      database:
        condition: service_started

Step 2: Start the Directus installation

In your terminal, navigate to the directus-docker folder and run:

docker-compose up

Step 3: Access Directus

Open http://localhost:8055 to access Directus. Use the credentials defined in the docker-compose.yml file.

The docker-compose.yml file also includes an Adminer image. You can launch Adminer at http://localhost:8008 to access the database. In a production environment, it’s better not to run Adminer by default, since it increases the server’s attack surface.

Additional Directus instances

To create more Directus instances, simply copy the directus-docker folder, give it a new name, and repeat Step 2. To use Directus in production, you’d typically set up an Nginx reverse proxy in another container. That’s where you can add security features such as a bot blocker and configure SSL. I’ll cover that in a future article.