Search code examples
dockerrabbitmqamqpdocker-composedocker-container

RabbitMQ inside docker won't end gracefully and cannot reconnect


I am trying to do RPC with RabbitMQ inside 2 docker containers. I have set them up as follows:

chindow:
 image: bablot/chindow
 ports:
   - "9999:9999"
 links:
   - rabbitmq:amq

rabbitmq:
 image: rabbitmq:3
 ports:
   - "15672:15672"

Everything works as expected initially, but then, when I shut down the system with ctrl+c it results in the following error:

babelotserver_rabbitmq_1 exited with code 143

and then when I proceed to reboot the system:

chindow_1  | { [Error: connect ECONNREFUSED 172.17.0.3:5672]
             code: 'ECONNREFUSED',
             errno: 'ECONNREFUSED',
             syscall: 'connect',
             address: '172.17.0.3',
             port: 5672 }

EDIT:

When I docker stop rabbitmq I get code 143 When I docker stop node.js I get code 0

Why are these 2 different? Is this meaningful?


Solution

  • Make sure you are using docker-compose format Version 2.

    It will create a bridge network: see "Networking in Compose"

    That will allow your containers to stop and re-start while still being able to see/contact each other.

    By default Compose sets up a single network for your app.
    Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.