directus-sync icon indicating copy to clipboard operation
directus-sync copied to clipboard

Docker instance: always install directus-sync after starting container

Open bartrail opened this issue 8 months ago • 1 comments

Hi there,

don't know if it is a bug or if I am just doing it wrong. Maybe you guys can help me out :)

I run directus-sync with the provided docker image from tractr/directus-sync:11.6.1. Everything is booting up and working fine so far. But when I try to run any commands from outside like docker compose exec directus npx directus-sync help I get the prompt that directus-sync is not available and needs to be installed:

Need to install the following packages:
[email protected]
Ok to proceed? (y) 

I know that I can run the command like this docker compose exec directus npx --yes directus-sync help to install it without asking, but this feels wrong, as I would guess it is already installed in the provided image.

I also tried the custom docker image version with the same result.

But when directus-sync is installed, everything works as expected, I can pull and push configs, seeds etc. Sharing the database schema across the team. Everything works out well so far. I need to develop some custom directus extensions for my current project, so I am a bit worried why directus-sync is not installed after booting up the container as expected.

For completenes, this is my docker-compose.yml:

services:
  proxy:
    image: caddy:2
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./docker/dev/Caddy/Caddyfile:/etc/caddy/Caddyfile
      - ./docker/dev/Caddy/data:/data
      - caddy_config:/config

  directus:
    image: 'tractr/directus-sync:11.6.1'
#    build:
#      context: .
#      dockerfile: Dockerfile
    volumes:
      - './directus/uploads:/directus/uploads'
#      - './directus/extensions:/directus/extensions'
      - './directus/templates:/directus/templates'
      - './directus/config:/directus/directus-config'
      - './directus/directus-sync.config.json:/directus/directus-sync.config.json:ro'
      - './directus/directus-sync.config.dev.json:/directus/directus-sync.config.dev.json:ro'
      - './directus/directus-sync.config.staging.json:/directus/directus-sync.config.staging.json:ro'
    ports:
      - 8055:8055
    environment:
      - SERVICE_FQDN_DIRECTUS_8055
      - KEY=$SERVICE_BASE64_64_KEY
      - SECRET=${SERVICE_BASE64_64_SECRET}
      - 'ADMIN_EMAIL=${ADMIN_EMAIL:[email protected]}'
      - ADMIN_PASSWORD=${SERVICE_PASSWORD_ADMIN}
      - DB_CLIENT=postgres
      - DB_HOST=postgresql
      - DB_PORT=5432
      - 'DB_DATABASE=${POSTGRESQL_DATABASE:-directus}'
      - DB_USER=$SERVICE_USER_POSTGRESQL
      - DB_PASSWORD=$SERVICE_PASSWORD_POSTGRESQL
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - WEBSOCKETS_ENABLED=true
      - EXTENSIONS_AUTO_RELOAD=true
      - MARKETPLACE_TRUST=all
      - QUERY_LIMIT_MAX=10000
    healthcheck:
      test:
        - CMD
        - wget
        - '-q'
        - '--spider'
        - 'http://127.0.0.1:8055/admin/login'
      interval: 5s
      timeout: 20s
      retries: 10
    depends_on:
      postgresql:
        condition: service_healthy
      redis:
        condition: service_healthy
  postgresql:
    image: 'postgis/postgis:16-3.4-alpine'
    platform: linux/amd64
    ports:
      - 5432:5432
    volumes:
      - 'directus-postgresql-data:/var/lib/postgresql/data'
    environment:
      - 'POSTGRES_USER=${SERVICE_USER_POSTGRESQL}'
      - 'POSTGRES_PASSWORD=${SERVICE_PASSWORD_POSTGRESQL}'
      - 'POSTGRES_DB=${POSTGRESQL_DATABASE:-directus}'
    healthcheck:
      test:
        - CMD-SHELL
        - 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}'
      interval: 5s
      timeout: 20s
      retries: 10
  redis:
    image: 'redis:7-alpine'
    command: 'redis-server --appendonly yes'
    volumes:
      - 'directus-redis-data:/data'
    healthcheck:
      test:
        - CMD
        - redis-cli
        - ping
      interval: 5s
      timeout: 20s
      retries: 10

volumes:
  caddy_data:
  caddy_config:
  directus-postgresql-data:
  directus-redis-data:

Some explanations:

The commented out line in volumes # - './directus/extensions:/directus/extensions' was a test because with the installation of directus-extension-sync - otherwise it would not work at all (see the screenshot) Image

I guess that I can create my custom directus extensions in this directory and then mount it to the directus container - which would be missing out directus-extension-sync then..

It's a bit confusing :D At least for me..

bartrail avatar Apr 30 '25 06:04 bartrail

HI @bartrail There are 2 packages:

  • directus-extension-sync which is an extension for Directus (pre-installed in the Docker image)
  • direcuts-sync which is a CLI installed with NPX

If you run the CLI inside the Docker container, it is not installed yet.

EdouardDem avatar Sep 25 '25 03:09 EdouardDem