I am fairly new to docker and I am learning about rabbitMQ. So far I have been able to run rabbitMQ, in the form of the python libary pika, on my ubuntu vm. This worked with no problems at all but I have now put it onto a small app in docker and does not work.
The problem seems to be in the set up and it all ways fails this line of code:
connection = pika.BlockingConnection(pika.ConnectionParameters(
        host=HOST, port=80, credentials=credentials))
The Variables being imported:
USER = "test"
PASS = "testpass1"
HOST = "dockerhost"
The file:
import pika
from settings import USER, PASS, HOST
def send(message):
    message = str(message)
    print 'trying: credentials = pika.PlainCredentials(username=USER, password=PASS)'
    try:
        credentials = pika.PlainCredentials(username=USER, password=PASS)
    except Exception:
        print 'Failed'
        print str(Exception)
        return 'Failed on: credentials = pika.PlainCredentials(username=USER, password=PASS) \n' + str(Exception.message)
    print 'trying: connection = pika.BlockingConnection(pika.ConnectionParameters(host=HOST, port=80, credentials=credentials))'
    try:
        connection = pika.BlockingConnection(pika.ConnectionParameters(
            host=HOST, port=80, credentials=credentials))
    except Exception:
        print 'Failed'
        print str(Exception)
        return 'Failed on: connection = pika.BlockingConnection(pika.ConnectionParameters(host=HOST, port=80, credentials=credentials)) \n' + str(Exception.message)
    channel = connection.channel()
    channel.queue_declare(queue='hello')
    channel.basic_publish(exchange='',
                      routing_key='hello',
                      body=message)
    connection.close()
    return "Message Sent"
Within this code it always fails on the line:
connection = pika.BlockingConnection(pika.ConnectionParameters(
        host=HOST, port=80, credentials=credentials))
And finally the Dockerfile:
FROM ubuntu
MAINTAINER Will Mayger
RUN echo "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main universe" >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y tar git curl nano wget dialog net-tools build-essential
RUN apt-get install -y python python-dev python-distribute python-pip
RUN git clone https://github.com/CanopyCloud/microservice-python
RUN pip install -r /microservice-python/requirements.txt
EXPOSE 80
WORKDIR /microservice-python/
CMD sudo rabbitmqctl add_user test testpass1
CMD sudo rabbitmqctl add_vhost myvhost
CMD sudo rabbitmqctl set_permissions -p myvhost test ".*" ".*" ".*"
CMD sudo rabbitmq-server
CMD python /microservice-python/server.py
For any additional information all the files are located on: https://github.com/CanopyCloud/microservice-python
                        
Your
Dockerfileis not correct.Try this instead:
The reason it isn't/wasn't correct was because you were defning multiple
CMD(s) in yourDockerfile. I'm pretty sure docker will only set the last command in the resulting image andCMDdoes not "run" things as part of the image build process;RUNdoes.CMDsets up the "command" that the image runs as part ofdocker run <image>Also you seem to have combined RabbitMQ and your Python app into the one Docker Image/Container; which isn't really the best thing to do here.
You should instead split this out into two images.
And use "Docker Links" via
docker run --linkto link the containers together.You can build an Image for your Python APp quite easily by using something like this as a separate
Dockerfilefor your Python App: