0

I'm trying to run my image container that ran without any error on the docker desktop. and when I try to run the same command and repository on Digital ocean I got this error

error: connect ECONNREFUSED 127.0.0.1:3306
Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
    --------------------
    at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/app/node_modules/mysql/lib/Connection.js:116:18)
    at /app/node_modules/knex/lib/dialects/mysql/index.js:56:18
    at new Promise (<anonymous>)
    at Client_MySQL.acquireRawConnection (/app/node_modules/knex/lib/dialects/mysql/index.js:51:12)
    at create (/app/node_modules/knex/lib/client.js:237:39)
error Command failed with exit code 1.

docker-compose :

version: "3"
services:
  mysql:
    image: mysql
    command: mysqld --default-authentication-plugin=mysql_native_password
    volumes:
      - ./data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: strapi
      MYSQL_DATABASE: strapi
      MYSQL_USER: strapi
      MYSQL_PASSWORD: strapi

  strapi:
    image: strapiproje:latest
    environment:
      DATABASE_CLIENT: mysql
      DATABASE_HOST: mysql
      DATABASE_PORT: 3306
      DATABASE_NAME: strapi
      DATABASE_USERNAME: strapi
      DATABASE_PASSWORD: strapi
      DATABASE_SSL: "false"
    volumes:
      - ./app:/srv/app
    ports:
      - "1337:1337"
    depends_on:
      - mysql

I also try DATABASE_HOST: 127.0.0.1 but nothing change any one has nay suggestion for me?

Mr.D
  • 3
  • 1
  • 4
  • Are you sure it works locally? That `DATABASE_HOST` setting doesn't look right to me; I'd expect it'd need to be the other Compose service's name `mysql`. Also see [Docker - SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306](https://stackoverflow.com/questions/53988649/docker-sequelizeconnectionrefusederror-connect-econnrefused-127-0-0-13306). – David Maze Mar 31 '22 at 21:36
  • Actually, I set it as DATABASE_HOST : mysql in the first place but this error also occur. Anyway I'll try that again – Mr.D Mar 31 '22 at 22:48

1 Answers1

1

You are probably missing a map from the port 3306 of your host machine to the same port in your docker container. Your docker-compose.yml file should look like this:

version: "3"
services:
  mysql:
    image: mysql
    command: mysqld --default-authentication-plugin=mysql_native_password
    volumes:
      - ./data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD: strapi
      - MYSQL_DATABASE: strapi
      - MYSQL_USER: strapi
      - MYSQL_PASSWORD: strapi
    ports:
      - "3306:3306"   <----- notice these lines


  strapi:
    image: strapiproje:latest
    environment:
      DATABASE_CLIENT: mysql
      DATABASE_HOST: mysql
      DATABASE_PORT: 3306
      DATABASE_NAME: strapi
      DATABASE_USERNAME: strapi
      DATABASE_PASSWORD: strapi
      DATABASE_SSL: "false"
    volumes:
      - ./app:/srv/app
    ports:
      - "1337:1337"
    depends_on:
      - mysql
Igor Perić
  • 171
  • 1
  • 8