Forest backend in docker: connect refused to local MySQL

Feature(s) impacted

I am attempting to configure and run forest admin on my local ubuntu22.04 machine.

I can start the backend docker container:

But if I attempt to use the web admin I get a connection refused error:

Observed behavior

I start the backend docker container and go to the web interface at https://app.forestadmin.com/ and I get the error: " The request to your server either failed or returned invalid data. Please check your console logs to get more information."

Looking at the terminal it displays a connection error when attempting to contact the MySQL server on my local machine.

Expected behavior

I should start the backend, the backend should connect to my DB, and I should see lots of useful information in the web interface.

Failure Logs

elvis  | [forest] 🌳🌳🌳  Unexpected error: connect ECONNREFUSED 127.0.0.1:3306
elvis  | {
elvis  |   "name": "SequelizeConnectionRefusedError",
elvis  |   "parent": {
elvis  |     "errno": -111,
elvis  |     "code": "ECONNREFUSED",
elvis  |     "syscall": "connect",
elvis  |     "address": "127.0.0.1",
elvis  |     "port": 3306,
elvis  |     "fatal": true
elvis  |   },
elvis  |   "original": {
elvis  |     "errno": -111,
elvis  |     "code": "ECONNREFUSED",
elvis  |     "syscall": "connect",
elvis  |     "address": "127.0.0.1",
elvis  |     "port": 3306,
elvis  |     "fatal": true
elvis  |   },
elvis  |   "stack": "SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306\n    at /usr/src/app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:123:19\n    at tryCatcher (/usr/src/app/node_modules/sequelize/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/usr/src/app/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:547:31)\n    at Promise._settlePromise (/usr/src/app/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:604:18)\n    at Promise._settlePromise0 (/usr/src/app/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:649:10)\n    at Promise._settlePromises (/usr/src/app/node_modules/sequelize/node_modules/bluebird/js/release/promise.js:725:18)\n    at _drainQueueStep (/usr/src/app/node_modules/sequelize/node_modules/bluebird/js/release/async.js:93:12)\n    at _drainQueue (/usr/src/app/node_modules/sequelize/node_modules/bluebird/js/release/async.js:86:9)\n    at Async._drainQueues (/usr/src/app/node_modules/sequelize/node_modules/bluebird/js/release/async.js:102:5)\n    at Immediate.Async.drainQueues [as _onImmediate] (/usr/src/app/node_modules/sequelize/node_modules/bluebird/js/release/async.js:15:14)\n    at processImmediate (internal/timers.js:464:21)"

Context

  • Project name: ELVIS
  • Team name: Operations
  • Environment name: Development
  • Agent type & version:
  • Recent changes made on your end if any: …

I am able to connect to the mysql DB from the command line using:

mysql -u root -pi49^Vq6@BYcw -h 127.0.0.1 -P 3306 marketplace

So I know that my DB is up and running. It’s almost as if the docker container is attempting to talk to a DB inside the container and not the DB running outside the container?

Here is the docker compose file:

version: '3.4'
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      network: host
    container_name: elvis
    environment:
      - APPLICATION_PORT=${APPLICATION_PORT}
      - APPLICATION_URL=${APPLICATION_URL}
      - DATABASE_URL=${DATABASE_URL}
      - DATABASE_SSL=${DATABASE_SSL}
      - FOREST_AUTH_SECRET=${FOREST_AUTH_SECRET}
      - FOREST_ENV_SECRET=${FOREST_ENV_SECRET}
    ports:
      - "${APPLICATION_PORT}:${APPLICATION_PORT}"
    volumes:
      - ./:/usr/src/app
      - /usr/src/app/node_modules

Hey @jester66, and welcome to our community :wave:

By any chance, did you try running the nodejs process instead of the Docker onboarding?
My guess here is that 127.0.0.1 refers to the localhost address inside your forest container, and that your 127.0.0.1:3306 inside the forestadmin agent container doesn’t exist.

I’m pretty sure on windows/macos you could use host.docker.internal to refer to host binded port, but I’m also pretty sure this is not available on linux based systems.

Could you try making both container run on the same network ?

Thanks in advance.

Hi @jeffladiray , thanks for your reply. I looked around at the various stack exchange answers to do with exposing the host ports to the docker container and it seems that host.docker.internal should be working on linux for some time now.

Regardless, I set the mysql DB to listen to IP4 addresses and not just localhost and set the DB IP to be the IP of my local machine and now I can connect:

It’s not a good solution, I’d like to switch my DB back to only localhost connections.

I thought to run the docker solution because it would be simpler. I guess I was wrong.

Thank you for confirming the suspicion that it was a docker network issue. I wonder what I can change in the docker config to get localhost working properly?

1 Like

I did take your advice and ran a local npm install && npm run start which is up and running in no time.

1 Like

It’s not a good solution, I’d like to switch my DB back to only localhost connections.

Is it a database that runs locally (inside docker)? If yes, putting both container on the same network and using the docker FQDN instead of localhost:3306 should work as expected.

I thought to run the docker solution because it would be simpler. I guess I was wrong.

It really depend. We try to handle as much cases as possible when dealing with docker onboarding, but every docker setup is quite different so it can sometime be “harder” to fully setup exclusively via docker.
I usually recommand to onboarding using a classic npm/yarn setup (To reduce potential issue as the one you seems to have), then switch to docker once you had the opportunity to test our product. Our forest-cli tool will still generate a dockerfile than can run the agent, whenever you need it or not.

Sorry for the inconvenience generated here, I’ll check on my end if I can find anything to help with this process

Thank you for confirming the suspicion that it was a docker network issue. I wonder what I can change in the docker config to get localhost working properly?

Not super easy to answer without further informations regarding your project.

If you are still looking only for a development setup, I would suggest to create a new role in your database, allowing for connection outside of localhost only (Maybe 0.0.0.0 would work on linux as it does on mac/windows). If you are looking for a full docker setup, the first solution I mentionned may also work as well. Sharing a docker-compose for both container would ease the setup of the associated docker network I guess.

You can share more informations as DM regarding your setup that may help me assist you further if you need to.

Let me know if that helps.

1 Like

Hi again,

No, my DB is running on localhost, not in a docker container. I’m not a great fan of docker really, I was just attempting to find an easy way of getting forest admin setup so I could see what it might offer me. I had already attempted the other method of configuring forest, but it didn’t work, so I switched to running it as a microservice on top of the DB.

AFAIK, my system is a pretty vanilla ubuntu-22.04 install of mysql-server and a laravel/php/symphony app.

Now that I have npm up and running, I will probably just ignore docker again, and see what forest admin can offer. Thanks again.

2 Likes