Configuration with mysql and docker

Consider the docker-compose file below. Consider all the environment variables are defined in a separate .env file.

When I run docker-compose up, the mysql database is initialised correctly and I can connect to it from my host machine. n8n however throws the following error:

app_1  | There was an error initializing DB: connect ECONNREFUSED 172.22.0.2:3706
app_1  | 
app_1  | Stopping n8n...

Since DB_MYSQLDB_HOST=db which is the name of the service in the compose file, I’m at loss here.
Any suggestions?

Thank you


docker-compose.yml

version: "3"

volumes:
    n8n-db:

networks:
    n8n_net:
        driver: bridge

services:
  app:
    image: n8nio/n8n:latest
    container_name: "n8n_app"
    volumes:
      - ./dot-n8n:/home/node/.n8n
    environment:
      - N8N_BASIC_AUTH_ACTIVE=${N8N_BASIC_AUTH_ACTIVE}
      - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
      - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
      - DB_TYPE=mysqldb
      - DB_MYSQLDB_DATABASE=${MYSQL_DATABASE}
      - DB_MYSQLDB_HOST=db
      - DB_MYSQLDB_PORT=3706
      - DB_MYSQLDB_USER=${MYSQL_USER}
      - DB_MYSQLDB_PASSWORD=${MYSQL_PASSWORD}
    networks:
      - n8n_net
    ports:
      - 5678:5678
    depends_on:
     - db
    restart: unless-stopped
  db:
    image: mysql:5.7
    container_name: "n8n_db"
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    volumes:
      - n8n-db:/var/lib/mysql
    networks:
      - n8n_net
    ports:
      - 3307:3306
    restart: unless-stopped

Hey @joaomvfsantos!

Welcome to the community :slightly_smiling_face:

Looking at your docker-compose file, I think that the MySQL port (DB_MYSQLDB_PORT) is pointing to an incorrect port which is causing the error.

3 Likes

Hey @harshil1712

Thank you very much. I need some sleep. :confused:

That was indeed the problem.

Haha, I’ve been in similar situation :wink:

I am happy that we found the issue. Have fun!

1 Like