mysqldocker-composedirectus

Directus is not connecting with mysql over SSH server


I can't connect my directus project with mysql server. Getting connection refused error.

However when I'm running this command, I'm able to connect: mysql -u root -p -h localhost -P 3306

My docker-compose.yml file:

version: '3'
services:
 directus:
  container_name: directus
  image: directus/directus:latest
  ports:
    - 8055:8055
  environment:
   KEY: 'KEY_VALUE'
   SECRET: 'SECRET_VALUE'
   DB_CLIENT: 'mysql'
   DB_HOST: 'localhost'
   DB_PORT: '3306'
   DB_DATABASE: 'directus'
   DB_USER: 'root'
   DB_PASSWORD: 'MYSQL_PASSWORD'
   MYSQL_ROOT_PASSWORD: 'MYSQL_PASSWORD'
   MYSQL_USER: 'root'
   MYSQL_PASSWORD: 'MYSQL_PASSWORD'
   MYSQL_DATABASE: 'directus'
   ADMIN_EMAIL: 'admin@admin.com'
   ADMIN_PASSWORD: 'admin'
 networks:
  directus:

Solution

  • I actually faced the same issue and after terrible search finally I made the solution.

    You can connect to mysql by using this modified code:

    version: '3.8'
    services:
     mysql:
      image: mysql:5.7
      container_name: mysql
      restart: always
      environment:
       MYSQL_ROOT_PASSWORD: 'MYSQL_PASSWORD'
       MYSQL_DATABASE: 'directus'
      ports:
       - "3306:3306"
    
     directus:
      image: directus/directus:latest
      container_name: directus
      restart: always
      ports:
       - "8055:8055"
      environment:
       KEY: 'KEY_VALUE'
       SECRET: 'SECRET_VALUE'
       DB_CLIENT: 'mysql'
       DB_HOST: 'mysql'
       DB_PORT: '3306'
       DB_DATABASE: 'directus'
       DB_USER: 'root'
       DB_PASSWORD: 'MYSQL_PASSWORD'
       ADMIN_EMAIL: 'admin@admin.com'
       ADMIN_PASSWORD: 'admin'
      depends_on:
       - mysql
    
    networks:
     default:
      name: directus_network