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:// --recv EA312927
RUN echo "deb 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:

  • docker how to add host entry to generic image available in docker repository
  • How mongorestore DB with docker
  • Cannot download Docker images behind a proxy
  • How to create flexible onbuild docker image that uses env vars?
  • How to use docker v1 repository
  • What is the meaning of “sandbox” in “docker run” command?
  • 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: "", 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/'
    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.

  • Change volume configuration in docker-compose without losing the data
  • Bad substitution [duplicate]
  • Start an existing docker ubuntu container [duplicate]
  • NodeJS / Express cannot connect to mongodb running in docker
  • How to pass arguments to a Dockerfile?
  • Using docker gcplogs (Google Cloud Logging driver) on digital ocean with docker compose
  • 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/ --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/

    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.