自定义MongoDb泊坞窗图像

时间:2016-09-07 08:39:52

标签: mongodb docker

我已创建此Dockerfile以创建图像:

FROM mongo:2.6
MAINTAINER Living Digital Way
COPY ./init.ms .
RUN mongo < ./init.ms

init.ms就像:

use fdb;
db.col.insert({"name": "name1"...});
...

正如您所看到的,我正在尝试将一些数据添加到我的mongo实例中。

当我构建此图像时,我从Docker收到此消息:

Step 4 : RUN mongo < ./init.ms
04:34:47 
04:34:47  ---> Running in 96dd54d94bc6
04:34:47 
04:34:47 MongoDB shell version: 2.6.12
04:34:47 
04:34:47 connecting to: test
04:34:47 
04:34:47 2016-09-07T08:34:47.482+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
04:34:47 
04:34:47 2016-09-07T08:34:47.483+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
04:34:47 
04:34:47 [91mexception: connect failed
04:34:47 [0m
04:34:47 ERROR: Build step failed with exception

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

你应该先启动mongod。

FROM mongo:2.6
MAINTAINER Living Digital Way
COPY ./init.ms .
# assume you are in mongo bin directory
RUN mongod -f you-config-path/mongo.conf
RUN mongo < ./init.ms