我创建了这个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

有任何想法吗?

最佳答案

您应该首先启动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

关于mongodb - 自定义MongoDb Docker镜像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39365099/

10-11 07:55