0

I have a requirement to create a single docker image by merging both "RabbitMQ-management" and "MongoDB" images. Is it possible to do it?

I've tried with below Dockerfile and can able to access RabbitMQ, but mongodb is not working. Could you please help me.

# cat Dockerfile 
FROM rabbitmq:3.7.17

RUN rabbitmq-plugins enable --offline rabbitmq_management

# extract "rabbitmqadmin" from inside the "rabbitmq_management-X.Y.Z.ez" plugin zipfile
# see https://github.com/docker-library/rabbitmq/issues/207
RUN apt-get update && apt-get install -y gnupg2
RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 0C49F3730359A14518585931BC711F9BA15703C6 && \
gpg --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mongodb.gpg
ARG MONGO_PACKAGE=mongodb-org
ARG MONGO_REPO=repo.mongodb.org
ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO}
ENV MONGO_MAJOR 3.4
ENV MONGO_VERSION 3.4.18
RUN echo "deb http://$MONGO_REPO/apt/debian jessie/${MONGO_PACKAGE%-unstable}/$MONGO_MAJOR main" | tee "/etc/apt/sources.list.d/${MONGO_PACKAGE%-unstable}.list"
RUN echo "/etc/apt/sources.list.d/${MONGO_PACKAGE%-unstable}.list"
RUN apt-get update
RUN apt-get install -y ${MONGO_PACKAGE}=$MONGO_VERSION
RUN set -eux; \
        erl -noinput -eval ' \
                { ok, AdminBin } = zip:foldl(fun(FileInArchive, GetInfo, GetBin, Acc) -> \
                        case Acc of \
                                "" -> \
                                        case lists:suffix("/rabbitmqadmin", FileInArchive) of \
                                                true -> GetBin(); \
                                                false -> Acc \
                                        end; \
                                _ -> Acc \
                        end \
                end, "", init:get_plain_arguments()), \
                io:format("~s", [ AdminBin ]), \
                init:stop(). \
        ' -- /plugins/rabbitmq_management-*.ez > /usr/local/bin/rabbitmqadmin; \
        [ -s /usr/local/bin/rabbitmqadmin ]; \
        chmod +x /usr/local/bin/rabbitmqadmin; \
        apt-get update; apt-get install -y --no-install-recommends python ca-certificates; rm -rf /var/lib/apt/lists/*; \
        rabbitmqadmin --version

EXPOSE 15671 15672 27017

I'm using below command to run RabbitMQ (it is working)

# docker run -it -p 15672:15672 -p 5672:5672  --hostname my-rabbitmq image

Command to start Mongodb container (it is not working)

docker run -d -v /tmp/mongodb:/data/db -p 27017:27017 image mongod
ratnakar
  • 71
  • 1
  • 8
  • 3
    It is a bad practice. Why would you do that? Why not running the two containers? If you need to run them as a 'stack', use docker-compose – Chen A. Apr 24 '20 at 05:39
  • I agree with you. There is a requirement to run unit tests on DB and RabbitMQ, once code pushes by the developers. – ratnakar Apr 24 '20 at 05:47
  • A better way of doing this is declaring compose file, and bring up a 'stack' for the testing. Combining two separate images in a single container is not only bad practice, but will be huge pain to debug when things break. – Chen A. Apr 24 '20 at 05:49

1 Answers1

1

It is not impossible to achieve what you are asking, but I would say it's not the correct way of doing it. Docker provides isolation, and states that it should be one process per container. (should, not must).

If you follow this concept, it's easy to use other tools to bring up multiple containers together. For example, instead of complicated Dockerfile that merge two images you can specify a nice docker-compose.yml:

 version: '3'

  services:
    mongo:
      image: mongod
      volumes:
        - /tmp/mongodb:/data/db
      ports:
        - "27017:27017"
    rabbitmq:
      image: rabbitmq
      ports:
        - "15672:15672"
        - "5672:5672"
      depends_on:
        - mongo

Which is more readable IMO, and probably achieve the same outcome.

Chen A.
  • 10,140
  • 3
  • 42
  • 61