Can't connect to Azure SQL Server when running Directus from Docker

115 views Asked by At

I am using the Directus Docker container to get a project going. I however have modified my compose file to rather utilise mssql as my datastore. It all worked fine while using sqlite.

I've set up my Azure SQL Server and SQL Database on Azure Portal. I can connect to it just fine from SSMS, and if I simply run npx directus start within my project folder it connects just fine using the credentials from .env.

I am admittedly new to Docker, and I suspect my issue is related to me perhaps misunderstanding some core concept. I did update my SQL admin user's password for SQL Server on Azure, and I suspect that the password is cached somewhere. I've tried a few of the other suggestions on here such as docker compose up -d but no luck here either - it just can't connect from within that container.

Another possible issue is the firewall. I've added my public IP to the firewall already (hence can connect on SSMS). Does the container start up with its own internal IP? Or is it a port issue?

I've spent several hours on ChatGPT, forums, Discord now without much luck.

My docker-compose file looks like this:

version: '3'
services:
  directus:
    image: directus/directus:10.8.3
    ports:
      - 8055:8055
    volumes:
      - ./database:/directus/database
      - ./uploads:/directus/uploads
      - ./extensions:/directus/extensions
    environment:
      LOG_LEVEL: debug
      KEY: ${KEY}
      SECRET: ${SECRET}
      ADMIN_EMAIL: ${ADMIN_EMAIL}
      ADMIN_PASSWORD: ${ADMIN_PASSWORD}
      DB_CLIENT: ${DB_CLIENT}
      DB_HOST: ${DB_HOST}
      DB_PORT: ${DB_PORT}
      DB_DATABASE: ${DB_DATABASE}
      DB_USER: ${DB_USER}
      DB_PASSWORD: ${DB_PASSWORD}
      DB_OPTIONS__ENCRYPT: ${DB_OPTIONS__ENCRYPT}
      WEBSOCKETS_ENABLED: true

And my env file looks like this (redacted):

DB_CLIENT="mssql"
DB_HOST="xxx.database.windows.net"
DB_PORT="1433"
DB_DATABASE="xxx"
DB_USER="xxx"
DB_PASSWORD="xxx"
DB_OPTIONS__ENCRYPT="true"

This is the error I get:

directus-1  | ConnectionError: Login failed for user 'xxx'.
directus-1  |     at Login7TokenHandler.onErrorMessage (/directus/node_modules/.pnpm/[email protected]/node_modules/tedious/lib/token/handler.js:187:19)
directus-1  |     at Readable.<anonymous> (/directus/node_modules/.pnpm/[email protected]/node_modules/tedious/lib/token/token-stream-parser.js:18:33)
directus-1  |     at Readable.emit (node:events:517:28)
directus-1  |     at addChunk (node:internal/streams/readable:368:12)
directus-1  |     at readableAddChunk (node:internal/streams/readable:341:9)
directus-1  |     at Readable.push (node:internal/streams/readable:278:10)
directus-1  |     at next (node:internal/streams/from:98:31)
directus-1  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
directus-1  |   code: 'ELOGIN'
directus-1  | }
directus-1 exited with code 1
0

There are 0 answers