mongod doesn't stop (docker debian:wheezy)

I have the following Dockerfile:

FROM debian:wheezy

RUN apt-get update

RUN apt-get install -y apt-utils

RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.2 main" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
RUN apt-get update
RUN apt-get install -y mongodb-org

Then I build the image:

  • Access denied for mysql docker image in bamboo
  • How to run a docker containter linked to a previously created volume
  • Why other unrelated processes are killed when one process is killed in docker container
  • Docker container with Python Web App - Connect to Postgres on Host machine (OSX)
  • In Docker, why is it recommended to run `apt-get` update in the Dockerfile?
  • ansible_default_ipv4.address undefined in docker ubuntu
  • docker build -t my/image .
    

    and try to start and stop the server:

    $ docker run -it my/image
    root@35ba8193f979:/# service mongod start
    [ ok ] Starting database: mongod.
    root@35ba8193f979:/# service mongod stop
    [FAIL] Stopping database: mongod failed!
    

    As you can see, mongod fails to stop. I can verify this by running ps and grepping for the mongod process; it’s still there.

    Here’s the logs:

    root@fce8d9638ce4:/# cat /var/log/mongodb/mongod.log 
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten] MongoDB starting : pid=19 port=27017 dbpath=/var/lib/mongodb 64-bit host=fce8d9638ce4
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten] db version v3.2.9
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten] allocator: tcmalloc
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten] modules: none
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten] build environment:
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten]     distmod: debian71
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten]     distarch: x86_64
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten]     target_arch: x86_64
    2016-09-20T05:01:02.874+0000 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
    2016-09-20T05:01:02.893+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
    2016-09-20T05:01:03.087+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
    2016-09-20T05:01:03.087+0000 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
    2016-09-20T05:01:03.156+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
    

    I’ve googled for a solution already; most of the posts I find are very old, or don’t describe the same problem as mine. Any help is greatly appreciated.

  • Why >>> eval “$(docker-machine env default)” in a ansible playbook script return “No such file or directory”
  • Docker: execute a program that requires tty
  • ngx_http_userid module not generating $uid_got in running Docker container
  • Docker maximum offline containers
  • Memory snappiness docker
  • Dockerized Neo4j ignoring previous database
  • One Solution collect form web for “mongod doesn't stop (docker debian:wheezy)”

    There appears to be an issue with service mongod stop since internally it calls a command which looks similar to:

    start-stop-daemon --stop --pidfile /var/run/mongod.pid --user mongodb --exec /usr/bin/mongod

    but the start-stop-daemon command somehow cannot find the executable /usr/bin/mongod, so it failed to stop the process. You can see the service script in /etc/init.d/mongod.

    The solution that I found to be working is to call it without --exec directly from the command line:

    start-stop-daemon --stop --pidfile /var/run/mongod.pid

    and that seems to be able to stop the service properly.

    I believe this issue is not limited to MongoDB, since I found multiple references about services not able to be stopped.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.