0

I have already asked this question on serverfault.com. I am asking it here too as I see different set of questions in these 2 sites (it appears like they have different databases).

I have been trying to build an OS image from Fedora unsuccessfully to start the following:

  1. Systemd
  2. SSHD
  3. RabbitMQ
  4. MongoDB

I can get the first 3 (Systemd, SSHD and RabbitMQ-Server) to work. I can also get MongoDB to work within the container. However, I cannot get MongoDB to work along with other 3 services.

In addition, IP address doesn't show up when I try to "dockerize" MongoDB.

Am I missing something in the Dockerfile?

Here is my dockerfile:

FROM fedora:20
MAINTAINER “Ashfaque” <ashfaque@email.com>
ENV container docker
RUN yum -y update; yum clean all
RUN yum -y install systemd; yum clean all; \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;

# Dockerizing SSH - is working
RUN yum -y install openssh-server
RUN yum -y install openssh-clients
RUN mkdir /var/run/sshd
RUN systemctl enable sshd.service
RUN echo 'root:mypassword' |chpasswd
EXPOSE 22

# Dockerizing RabbitMQ - is working
RUN yum -y install rabbitmq-server
EXPOSE 5672 15672
RUN systemctl enable rabbitmq-server

# Dockerizing MongoDB - is NOT WORKING
RUN yum -y install mongodb-server
RUN yum -y install boost
RUN yum -y install scons
# Create the MongoDB data directory
RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb
RUN sed -i 's/dbpath =\/var\/lib\/mongodb/dbpath =\/data\/db/' /etc/mongodb.conf
# Expose port 27017 from the container to the host
EXPOSE 27017
# Set usr/bin/mongod as the dockerized entry-point application
ENTRYPOINT ["/usr/bin/mongod"]
#CMD ["--port", "27017", "--dbpath", "/data/db", "--smallfiles", "--fork", "--syslog"]
#RUN /usr/bin/mongod --smallfiles --port 27017 --dbpath /data/db --fork --syslog

VOLUME ["/sys/fs/cgroup", "/data/db", "/var/log/mongodb", "/usr/bin"]
CMD ["/usr/sbin/init"]

Docker Commands used to build are:

(1) docker build -t rabbitmq_mongo_heisenbug .

(2) docker run --privileged -d -e 'container=docker' -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 29022:22 -p 29672:15672 -p 29017:27017 rabbitmq_mongo_heisenbug

or.. (3) docker run --privileged -ti -e 'container=docker' -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 29022:22 -p 29672:15672 -p 29017:27017 rabbitmq_mongo_heisenbug

ivant
  • 3,909
  • 1
  • 25
  • 39
ashFAQue
  • 3
  • 1
  • 2
  • Some information on what exactly is failing while running / starting-up MongoDB will be useful to suggest anything. Any logs that point to that? are you able to install MongoDB and then failing to start it or the other way. – aks Jun 30 '14 at 05:21
  • When I run in interactive mode, it throws an error: "Invalid command: /usr/sbin/init". In the daemon more, I cannot SSH into the container (as it wouldn't have started and IP address would not be taken up). – ashFAQue Jun 30 '14 at 05:40

1 Answers1

2

You are using both ENTRYPOINT and CMD in your Dockerfile. This means, that docker will run /usr/bin/mongod with default parameter /usr/sbin/init. I'm pretty sure this is not what you want.

Docker will run as long as the command you specified is running. I'm not sure about /usr/bin/mongod, but if it runs in daemon mode (that is, spawn a process and return), then the container will stop running right away. The spawned processes will be terminated. The same is true for /usr/sbin/init or for any other command you specify. You can write a small shell script, which spawns the processes and runs one in the foreground, or you can use runit, or some similar tool.

Also, you probably don't need to run sshd in your container. See here why.

ivant
  • 3,909
  • 1
  • 25
  • 39
  • Thanks for the informative response. SSH: I need SSH, as I want 3 of my daemons to run within the container (along with rabbitmq/etc), & later run 2 other applications after logging in. I have a question here - Is it not a right approach to run several daemons? MongoDB: I did try having CMD (it is commented out to indicate some of the trial-and-error scenarios that I had attempted. e.g. I had 1 CMD separated by commas) CMD ["/usr/sbin/init"] ["/usr/sbin/init", "--port", "27017", "--dbpath", "/data/db", "--smallfiles", "--fork", "--syslog"] Is there a right approach for this scenario? – ashFAQue Jun 30 '14 at 11:54
  • Actually, your response answered my question. Thanks! I could set it up after reading your response. Here is what I did: 1. Commented out ENTRYPOINT 2. Run the following commands in the container: chown mongod:mongod /data/db chmod 0755 /data/db useradd mongodb groupadd mongodb chown mongod:mongod /data/db systemctl start mongod.service touch /data/db/mongod.lock chown mongod:mongod /data/db/mongod.lock /usr/bin/mongod --smallfiles I pulled this out from history in the container. Some might be redundant and not necessary; they throw out an error anyways. – ashFAQue Jul 02 '14 at 22:23