Installation de Directus via Docker

Bonjour tout le monde,

cela a été un grand sujet lors du code & fun, mais je pense que j’ai trouvé ce qu’il faut pour installer Directus et tout ce qu’il faut via Docker.

Donc voici le fichier docker-compose.yml

version: "3"
services:
     database:
          container_name: database
          image: mariadb:latest
          env_file:
               - .env
          networks:
               - directus
          ports:
               - 3306:3306
          volumes:
               - ./data/database:/var/lib/mysql

     cache:
          container_name: cache
          image: redis:6
          networks:
               - directus

     directus:
          container_name: directus
          image: directus/directus:latest
          ports:
               - 8055:8055
          volumes:
               # By default, uploads are stored in /directus/uploads
               # Always make sure your volumes matches the storage root when using
               # local driver
               - ./uploads:/directus/uploads
               # Make sure to also mount the volume when using SQLite
               # - ./database:/directus/database
               # If you want to load extensions from the host
               - ./extensions:/directus/extensions
          networks:
               - directus
          depends_on:
               - cache
               - database
          restart: unless-stopped
          environment:
               KEY: "255d861b-5ea1-5996-9aa3-922530ec40b1"
               SECRET: "6116487b-cda1-52c2-b5b5-c8022c45e263"

               DB_CLIENT: ${DB_CLIENT}
               DB_HOST: database
               DB_PORT: ${DB_PORT}
               DB_DATABASE: ${MYSQL_DATABASE}
               DB_USER: ${MYSQL_USER}
               DB_PASSWORD: ${MYSQL_PASSWORD}

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

               ADMIN_EMAIL: ${ADMIN_EMAIL}
               ADMIN_PASSWORD: ${ADMIN_PASSWORD}

               # Make sure to set this in production
               # (see https://docs.directus.io/self-hosted/config-options#general)
               # PUBLIC_URL: 'https://directus.example.com'

networks:
     directus:

et voici le fichier .env qui va avec

#MARIADB
MYSQL_ROOT_PASSWORD=secret
MYSQL_DATABASE=directus
MYSQL_USER=directus_db_user
MYSQL_PASSWORD=directus_db_password
MYSQL_AUTHENTICATION_PLUGIN="mysql_native_password"

#DIRECTUS
DB_CLIENT=mysql
DB_PORT=3306
[email protected]
ADMIN_PASSWORD=d1r3ctu5

# CACHE
CACHE_ENABLED=true
CACHE_STORE=redis
CACHE_REDIS=redis://cache:6379
CACHE_AUTO_PURGE=true
CACHE_TTL=1d

après c’est la première fois que j’utilise docker donc il y a peut être des optimisations à faire.

2 « J'aime »

Afin de compléter, voici une version pour mysql :

version: "3"

networks:
    default:
        name: ${STACK_PRFX}

services:
    database:
        container_name: ${STACK_PRFX}-database
        image: mysql:8.0
        ports: 
          - 3306:3306
        volumes:
            - ./data:/var/lib/mysql
        command:
            [
                "--character-set-server=utf8mb4",
                "--collation-server=utf8mb4_unicode_ci",
                "--default-authentication-plugin=mysql_native_password",
            ]
        env_file:
            - .env

    # Cache
    cache:
        container_name: ${STACK_PRFX}-cache
        image: redis:7.0-alpine

    # Directus
    directus:
        container_name: ${STACK_PRFX}-directus
        image: directus/directus:latest
        restart: unless-stopped
        ports:
            - 8055:8055
        volumes:
            - ./uploads:/directus/
            - ./extensions:/directus/extensions
        depends_on:
            - cache
            - database
        env_file:
            - .env

le fichier .env :

# .env

# Docker Compose

STACK_PRFX=directus-app


# Directus

KEY='key'
SECRET='key'

PUBLIC_URL="http://url:8055"

DB_CLIENT=mysql
DB_HOST=database
DB_PORT=3306
DB_DATABASE=directus
DB_USER=directus
DB_PASSWORD=password

CACHE_ENABLED=true
CACHE_STORE=redis
CACHE_REDIS=redis://cache:6379

[email protected]
ADMIN_PASSWORD=passdirectus


# MySQL

MYSQL_ROOT_PASSWORD=rootpassword
MYSQL_USER=${DB_USER}
MYSQL_PASSWORD=${DB_PASSWORD}
MYSQL_DATABASE=${DB_DATABASE}

# MySQL image by bitnami
MYSQL_AUTHENTICATION_PLUGIN="mysql_native_password"

Il y a eu une mise jour du docker directus en 10.4.0 qui change quelques petites choses Release note

Voici donc mon docker mis à jour

version: "3"
services:
     database:
          container_name: database
          image: mariadb:latest
          env_file:
               - .env
          ports:
               - 65050:3306
          volumes:
               - ./data/database:/var/lib/mysql

     cache:
          container_name: cache
          image: redis:latest

     directus:
          container_name: directus
          image: directus/directus:latest
          ports:
               - 8055:8055
          volumes:
               # By default, uploads are stored in /directus/uploads
               # Always make sure your volumes matches the storage root when using
               # local driver
               - ./uploads:/directus/uploads
               # Make sure to also mount the volume when using SQLite
               # - ./database:/directus/database
               # If you want to load extensions from the host
               - ./extensions:/directus/extensions
          depends_on:
               - cache
               - database
          restart: unless-stopped
          environment:
               KEY: "KEY"
               SECRET: "SECRET"

               # DB CONFIGURATION
               DB_CLIENT: ${DB_CLIENT}
               DB_HOST: database
               DB_PORT: ${DB_PORT}
               DB_DATABASE: ${MYSQL_DATABASE}
               DB_USER: ${MYSQL_USER}
               DB_PASSWORD: ${MYSQL_PASSWORD}

               REDIS_HOST: cache
               REDIS_PORT: 6379

               CACHE_STORE: "redis"
               RATE_LIMITER_STORE: "redis"
               SYNCHRONIZATION_STORE: "redis"
               MESSENGER_STORE: "redis"

               # DEFAULT ADMIN USER
               ADMIN_EMAIL: ${ADMIN_EMAIL}
               ADMIN_PASSWORD: ${ADMIN_PASSWORD}

               #WEBSOCKETS
               WEBSOCKETS_ENABLED: "true"
               WEBSOCKETS_REST_ENABLED: "true"
               WEBSOCKETS_REST_AUTH: "handshake"
               WEBSOCKETS_REST_AUTH_TIMEOUT: 15

               #STORAGE
               STORAGE_LOCATIONS: "local"
               STORAGE_LOCAL_DRIVER: "local"
               STORAGE_LOCAL_ROOT: "./uploads"

     # Make sure to set this in production
     # (see https://docs.directus.io/self-hosted/config-options#general)
     # PUBLIC_URL: 'https://directus.example.com'

networks:
     default:
          name: ${STACK_PRFX}

et le .env

STACK_PRFX=commercant

#MARIADB
MYSQL_ROOT_PASSWORD=secret
MYSQL_DATABASE=directus
MYSQL_USER=directus
MYSQL_PASSWORD=directus_user_password
MYSQL_AUTHENTICATION_PLUGIN="mysql_native_password"

#DIRECTUS
DB_CLIENT=mysql
DB_PORT=3306
[email protected]
ADMIN_PASSWORD=admin_password

# CACHE
CACHE_ENABLED=true
CACHE_STORE=redis
CACHE_REDIS=redis://commercant-cache:6379
CACHE_AUTO_PURGE=true
CACHE_TTL=1d
1 « J'aime »

Hello @jmjoary !

en gros la modif c’est essentiellement avec le cache ? Donc pour mettre à jour sur le VPS, il faut modifier le fichier docker, puis suivre la procédure standard en ssl :

Backup your project
Run npm update
Run npx directus database migrate:latest to update the DB

Je saisie les commandes telle quelles ? on ajoute Sudo avant ?

autre question (désolé) :

networks:
    default:
        name: ${STACK_PRFX}

il faut retirer le network ?

Merci !

Bonjour,
Voici un exemple de docker pour PostgreSQL. Sauf je n’arrive pas à le faire marcher. Une idée ?

version: "3" # docker-compose up
services:
  database:
    image: postgis/postgis:15-master
    volumes:
      - ./data/database:/var/lib/postgresql/data # avant up, mkdir data puis data/database
    environment:
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "my_password"
      POSTGRES_DB: "mydb"

  cache:
    image: redis:6

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

      DB_CLIENT: "pg"
      DB_HOST: "database"
      DB_PORT: "5432"
      DB_DATABASE: "mydb"
      DB_USER: "postgres"
      DB_PASSWORD: "my_password"

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

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

En repartant de zéro et réinstallant Docker, j’accède bien maintenant avec pgAdmon4 à la base correctement créée par Directus.