Skip to content

Instantly share code, notes, and snippets.

@kunalkushwaha
Created February 13, 2020 00:54
Show Gist options
  • Save kunalkushwaha/ff2f12ce69de7369febe9a4008043c60 to your computer and use it in GitHub Desktop.
Save kunalkushwaha/ff2f12ce69de7369febe9a4008043c60 to your computer and use it in GitHub Desktop.

Create container:

$ docker run -d --hostname my-rabbit --name some-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management

Here the default settings include user: user pass: user rabbitmq access port : 5672 rabbitmq mgmnt GUI port : 15672

You can browse the mgmnt GUI using http://localhost:15672/

copy send and recive example of hello-world exmaple from this tutorial https://www.rabbitmq.com/tutorials/tutorial-one-go.html

@kunalkushwaha
Copy link
Author

@kunalkushwaha
Copy link
Author

for compose see example in https://hub.docker.com/r/bitnami/rabbitmq/

@kunalkushwaha
Copy link
Author

kunalkushwaha commented Feb 13, 2020

in your program folder this should be structure

~/work/send ⌚ 11:14:54
$ ll
total 24K
-rw-r--r-- 1 kunal kunal  240 Feb 13 11:13 Dockerfile
-rw-r--r-- 1 kunal kunal   13 Feb 13 10:27 requirements.txt
-rw-r--r-- 1 kunal kunal  321 Feb 13 09:57 send-py.py
  • requirements.txt will include all packages you need to install for your program.
  • Dockerfile will package you program will also dependency in image.
$ cat requirements.txt 
pika == 1.1.0

$ cat Dockerfile 
FROM python:2.7

ADD requirements.txt .
RUN pip install -r requirements.txt
RUN mkdir /app
ADD send-py.py /app 
WORKDIR /app

CMD ["python", "./send-py.py"]

build image

$ docker build -t rmq-send .

Now, your rmq server and client programs should run in same network.
Since in above example, the rmq server is exposed on host network, to access that, you need to run this client container with host network.

$ docker run --net=host rmq-send:latest
 [x] Sent 'Hello World!'

In actual deployment, you need to create a docker network, and put all server clients on that network, so all clients can access the server.
check the bitnami page mentioned in above link. It is explained there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment