Home > Net >  Run MongoDB and RabbitMQ in Dockerfile
Run MongoDB and RabbitMQ in Dockerfile

Time:07-13

I'm trying to run MongoDB and RabbitMQ in docker using Dockerfile to test my python app. what's the best way to do that?

I did

FROM python:latest
RUN apt-get update
RUN apt-get install -y rabbitmq-server wget

RUN wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
RUN touch /etc/apt/sources.list.d/mongodb-org-5.0.list
RUN apt-get install -y mongodb-org
RUN sudo apt-get update
RUN sudo apt-get install -y mongodb-org

but it doesn't seem to work.

CodePudding user response:

Using Dockerfile you can only run one service at a time if you want to run 2 services at the same time, you have to use docker-compose

Here is a docker-compose.yaml, you can use to run 2 MongoDB and rabbit-mq at the same time.

version: '3.7'
services:
  mongodb_container:
    image: mongo:latest
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: rootpassword
    ports:
      - 27017:27017
    volumes:
      - mongodb_data_container:/data/db
  
  rabbitmq3:
    container_name: "rabbitmq"
    image: rabbitmq:3.8-management-alpine
    environment:
       - RABBITMQ_DEFAULT_USER=myuser
       - RABBITMQ_DEFAULT_PASS=mypassword
    ports:
       # AMQP protocol port
       - '5672:5672'
       # HTTP management UI
       - '15672:15672'

volumes:
  mongodb_data_container:
  • Related