Multiple images unable to communicate with one another

I’m trying to setup my full application stack using multiple images, to run end to end tests. My stack consists of a web front end, a backend API, as well as Redis and MySQL images. The tests are stored with the front end repo.

To bring up my stack, I need the backend API to be able to talk to the MySQL and Redis containers. I can connect to the MySQL and Redis containers from my primary container after they start, but it does not appear that the backend API can communicate with with MySQL/Redis on localhost:3306 and localhost:6379.

My config looks something like this:

version: 2
      - image: <dockerhub>/my-frontend:0.1
      - image: circleci/mysql:5.6.35                  # Listen on 3306
      - image: circleci/redis:4.0.11-alpine           # Listen on 6379
      - image: <dockerhub>/my-backend:0.1             # Listen on 3000
      - checkout
      - run:
          command: |
            # ... do some setup, then wait for services ....
            ./dockerize -wait tcp://localhost:3306 -timeout 60s  # this works here, but not from the backend entrypoint
            ./dockerize -wait tcp://localhost:6379 -timeout 60s  # this works here, but not from the backend entrypoint
            ./dockerize -wait tcp://localhost:3000 -timeout 60s  # this never establishes a connection
            # execute my tests...
            # yarn test

The container for the backend has an entrypoint script which waits for both MySQL and Redis instances to come up prior to starting:

./dockerize -wait tcp://localhost:3306 -timeout 60s
./dockerize -wait tcp://localhost:6379 -timeout 60s

However, the backend never comes up in this setup, presumably because those dockerize commands never return… I’m just wondering if this should work? Or do I have to use compose when I have containers that must talk to other containers, which are not the primary container?

Note: I’ve been able to get something similar working with docker-compose and the CircleCI remote docker support, but I’m trying to not use compose here.

1 Like

As a followup - my backend has a line like this in the Dockerfile:


It’s not clear to me from the docs how or if this is port being published. Ports 3306 and 6379 of the MySQL and Redis containers are accessible from the primary container, so there seems to be some magic happening behind the scenes to publish those, but I’m not sure if that’s true for my backend container as well. There doesn’t seem to be any directive, like “ports:” to publish ports in the config reference.

Hmm, right. There’s stuff that I would expect to work here, and stuff that should not:

  • Your dockerize to the backend should work. I wonder if internally you are just binding to localhost, I think you need to listen to “all interfaces”, like MySQL does by default.
  • However, if you need any of your last three to see each other, I don’t think that is going to work. They will be spun up on different machines, and the connectivity on localhost in the primary build container is probably down to some proxying magic that is not available elsewhere.

You could try fixing the first issue to see if the second one can be resolved, but I fear that it cannot.

A good alternative is to use Docker Compose, as you say.

1 Like

Okay, yeah that seems match what I’m seeing. For issue #1, I suspect the backend isn’t reachable because it fails to start, as a result of not being able to talk to the dependent services (MySQL and Redis).

I’m looking at Docker machine as a possible alternative.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.