Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to server on Docker from host machine?

Tags:

docker

Ok, I am pretty new to Docker world. So this might be a very basic question.

I have a container running in Docker, which is running RabbitMQ. Let's say the name of this container is "Rabbit-container".

RabbitMQ container was started with this command:

docker run -d -t -i --name rmq -p 5672:5672 rabbitmq:3-management 

Python script command with 2 args:

python ~/Documents/myscripts/migrate_data.py amqp://rabbit:5672/ ~/Documents/queue/

Now, I am running a Python script from my host machine, which is creating some messages. I want to send these messages to my "Rabbit-container". Hence I want to connect to this container from my host machine (Mac OSX).

Is this even possible? If yes, how?

Please let me know if more details are needed.

like image 664
Bhushan Avatar asked Jun 13 '16 23:06

Bhushan


People also ask

How do I get to Docker from host?

Accessing the Host With the Default Bridge Mode You just need to reference it by its Docker network IP, instead of localhost or 127.0. 0.1 . Your host's Docker IP will be shown on the inet line. Connect to this IP address from within your containers to successfully access the services running on your host.


1 Answers

So, I solved it by simply mapping the RMQ listening port to host OS:

docker run -d -t -i --name rmq -p 15672:15672 -p 5672:5672 rabbitmq:3-management

I previously had only -p 15672:15672 in my command. This is mapping the Admin UI from Docker container to my host OS. I added -p 5672:5672, which mapped RabbitMQ listening port from Docker container to host OS.

like image 152
Bhushan Avatar answered Sep 22 '22 23:09

Bhushan