Docker Compose – container receiving connection refused

Using docker-compose, I’m trying to run my API on a publicly available port 8080 and an sqs service on a privately available port 9324. The API needs to be able to communicate with the sqs service. In order to do so, I have set up the following docker-compose.yml:

version: '2'
    image: api
      - "8080:8080"
    image: pakohan/elasticmq

I have tried several iterations, including adding a link alias for the api:

  • Put haproxy outside docker compose
  • Jelastic Docker Nginx LoadBalancing with Horizontal Auto Scaling
  • How to run jar file using docker file in docker container
  • 'sudo: no tty present and no askpass program specified' error?
  • Docker Mac Beta using insecure Private Registry
  • RabbitMQ in Docker - user creation not persisted
  • links:
      - "sqs:localhost"

    and exposing the port for sqs:

      - "9324:9324"

    but neither seems to work. The API always gets a connection refused error when trying to communicate with the sqs service.

    When the sqs port is publicly exposed an API running outside of docker is able to communicate just fine (so the sqs service is getting initialized properly).

    Does anyone have any ideas as to how to solve this problem?

  • What does Kubernetes actually do? [closed]
  • Docker in production
  • /bin/sh: 1: ./configure: not found - dockerfile
  • Kubernetes application running on master - DaemonSet
  • Running a node app as a non root user in docker
  • Unable to install features in servicemix docker image: ERROR
  • One Solution collect form web for “Docker Compose – container receiving connection refused”

    Trying to trick the api container into connecting to sqs by telling it that it’s actually connecting to localhost isn’t going to work. You need to make sqs available to api under a name that doesn’t already have a special meaning, like:

        - sqs:original-name

    or even:

        - sqs

    which makes sqs accessible to api under the name “sqs“.

    Then, of course, you need to tell api that it should connect to port 9324 of original-name or sqs instead of port 9324 of localhost. How you do that depends on what api actually is.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.