Mongodb install fails in Ubuntu 14.04 docker container
ref: stack overflow
As mentioned from above, the reason is that you are trying to install a version packaged for Upstart init services, but ubuntu 14.04 still uses SysV init by default. The recommended approach is to use later version 3.2.x from here or if you are strict about the version, the fix is to use
deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen
instead of
deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse
Also, to get the mongod running when launching with docker run -d, you need to add a CMD to it. So, I modified and compiled a docker file to test this and looked like this:
FROM ubuntu:14.04
RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 \
&& echo "deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list \
&& apt-get update && apt-get -q -y install \
nodejs\
npm \
git \
mongodb-org
CMD ["mongod", "--dbpath", "."]
Note that, I didn't use the init to start the container as the init script places the mongod in the background (in addition to many other things). For docker containers to run continuously, the CMD script should be in foreground.
A clip from /etc/init.d/mongod start() note the --background there
# Start the process using the wrapper
start-stop-daemon --background --start --quiet --pidfile $PIDFILE \
--make-pidfile --chuid $DAEMONUSER \
--exec $NUMACTL $DAEMON $DAEMON_OPTS