0

I am using pika + rabbitMQ, deployed in a docker container, to provide the messaging infrastructure for a distributed system I am currently developing.

I have installed the relevant software etc however, I need a way to affix a static IP address to my RabbitMQ service (see snippet below) - but can't seem to be able to do so - and it seems this is not an easy thing to do (or might even be impossible to do).

I need a static IP address, so that code like that below, could work.

connection = pika.BlockingConnection(pika.ConnectionParameters(host='172.17.0.2'))

If it really is impossible to affix a static address to a running container - perhaps there is a way I could query docker (I think I remember seeing a flag to the inspect command that allows one to retrieve the IP address of the messaging container/service, which I can then pass through a shell script, to the producers/consumers.

Having said that, the latter approach is not robust against restarts (of messaging machine) etc, so I would prefer a static IP solution if possible.

Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
  • Have you considered, say, Docker Compose? That deals with assigning hostnames to containers, and then sets up inter-container name resolution for you. – Oliver Charlesworth Nov 16 '17 at 13:47
  • @OliverCharlesworth Yes I have. However, the system is quite complicated - it's more like a **cluster of subsystems** (whereas, if my understanding of `docker compose` is correct, it (i.e. docker compose) more closely mirrors a **single subsystem**. Since my knowledge of docker is quite shallow at the moment, I want to keep things very simple - at least, for now. – Homunculus Reticulli Nov 16 '17 at 14:26
  • You can affix a static IP to your container by using `-ip 10.0.0.6` in the `docker run` command. Also if you wish to use the docker-host IP, you might want to look into the `host` network driver. [link](https://docs.docker.com/engine/userguide/networking/#default-networks) – samprog Nov 16 '17 at 16:32
  • Possible duplicate of [Assign static IP to Docker container](https://stackoverflow.com/questions/27937185/assign-static-ip-to-docker-container) – yamenk Nov 16 '17 at 20:26

0 Answers0