本文介绍了自定义MongoDb Docker映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了这个Dockerfile来创建映像:

I've created this Dockerfile in order to create an image:

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实例添加一些数据.

As you can see I'm trying to add some data to my mongo instance.

在构建此映像时,我从Docker得到以下消息:

When I'm building this image I get this message from 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.

You should start mongod at first.

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 Docker映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 11:48