Mysql [ERROR] Error: connect ECONNREFUSED 127.0.0.1:3305

docker
mysql

#1

Hi there,

I am running a node app in circle-ci. To run my persistence tests, I need to spin up a docker image mysql 5.7 and the run migrations against it to make sure it is set up for testing.

My starting the container scripts succeeds, including pinging mysql to make sure it runs inside the docker image.

When the migration library attempts to make a connection from the base circle-ci image, I get the following error:
[ERROR] Error: connect ECONNREFUSED 127.0.0.1:3305

here is my job config:

test:
     working_directory: ~/my-project
     docker:
       - image: circleci/node:6.10
     branches:
       only:
         - circle-ci
     steps:
       - checkout
       - setup_remote_docker
       - attach_workspace:
           at: /home/circleci/my-project
       - run:
           name: test
           command: |
             ./scripts/ci/test.sh

DB config:

{
    "name": "test-db",
    "driver": "mysql",
    "host": "127.0.0.1",
    "port": 3305,
    "port_mapping": "3305:3306",
    "user": "test_user",
    "password": "test_password",
    "database": "tests"
  }

And here are all the env vars in the mysql docker image:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=44f1337d0a2f
MYSQL_RANDOM_ROOT_PASSWORD=yes
MYSQL_DATABASE=tests
MYSQL_USER=test_user
MYSQL_PASSWORD=test_password
MYSQL_ROOT_HOST=%
MYSQL_HOST=127.0.0.1
GOSU_VERSION=1.7
MYSQL_MAJOR=5.7
MYSQL_VERSION=5.7.18-1debian8
HOME=/root

This same config works fine when I set up on my local machine.

Any ideas what I am missing?

Thanks


#2

Where’s MySQL running? In another job?


#3

MySQL is running in a docker container that I spin up from my test script. As part of the script I also check and get success that the container I spin up is running, the mysql service in that container is running and the ping to the that database is returning that mysqld is up in running (ping is done from within the mysql container).

So I presume the problem is that the host container can not establish access to the container in which the mysql is running.

Thanks


#4

Oh okay so that’s the issue. Unless the Docker images are specified in the array up top under the Docker key, the containers can’t talk to each other via ports using the docker executor. You’ll want to use the machine executor instead.


#5