我有以下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
然后我建立了图像:
docker build -t my/image .
并尝试启动和停止服务器:
$ docker run -it my/image
root@35ba8193f979:/# service mongod start
[ ok ] Starting database: mongod.
root@35ba8193f979:/# service mongod stop
[FAIL] Stopping database: mongod failed!
如你所见,mongod未能停止。我可以通过运行ps
和grepping for mongod进程来验证这一点;它还在那里。
这是日志:
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
我已经用Google搜索了解决方案;我发现的大部分帖子都很旧,或者没有描述与我相同的问题。非常感谢任何帮助。
答案 0 :(得分:1)
service mongod stop
似乎存在问题,因为它在内部调用的命令类似于:
start-stop-daemon --stop --pidfile /var/run/mongod.pid --user mongodb --exec /usr/bin/mongod
但start-stop-daemon
命令以某种方式找不到可执行文件/usr/bin/mongod
,因此无法停止该过程。您可以在/etc/init.d/mongod
。
我发现工作的解决方案是直接从命令行调用它而不是--exec
:
start-stop-daemon --stop --pidfile /var/run/mongod.pid
这似乎能够正常停止服务。
我认为这个问题不仅限于MongoDB,因为我发现了多个关于服务无法停止的引用。