I am trying to create a mongodb container with an already configured user database (from Dockerfile).
Here is my Docker file:
FROM mongo:latest
RUN mongo localhost:27017 "db.help()"
(minimized it for testing purposes).
I keep getting the error:
connecting to: localhost:27017
2017-06-01T14:49:34.353+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-06-01T14:49:34.353+0000 E QUERY [thread1] Error: couldn't connect to server localhost:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed
... and the container is not created. I am not even sure how to check the logs, since I am building from the Dockerfile, and as soon as the container is not compiled, there is no way to enter the logbook.
However, if I remove this RUN command and do it manually:
docker -exec -it mongodb_container bash
mongo
> db.help()
... it works.
I tried to establish ownership of mongodb: mongodb and tried to move the log and db path to the ~ / db file without success.
PS: I am using docker-compose. I would like to do this with docker-compose so that developers do not have to manage things on their own.
, :
mongodb:
build: ./mongodb
ports:
- "27017:27017"
EDIT:
0.0.0.0:27017, :
MongoDB shell version v3.4.4
connecting to: 0.0.0.0:27017
2017-06-01T15:52:52.806+0000 E QUERY [thread1] Error: couldn't connect to server 0.0.0.0:27017, address resolved to 0.0.0.0 :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed
EDIT2:
Docker:
FROM mongo:latest
RUN mkdir -p /data/db2 \
&& echo "dbpath = /data/db2" > /etc/mongodb.conf \
&& chown -R mongodb:mongodb /data/db2
COPY . /data/db2
RUN mongod --fork --logpath /var/log/mongodb.log --dbpath /data/db2
MongoDB , :
mongodb_1 | 2017-06-01T15:55:52.955+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=64a317041edd
mongodb_1 | 2017-06-01T15:55:52.956+0000 I CONTROL [initandlisten] db version v3.4.4
mongodb_1 | 2017-06-01T15:55:52.956+0000 I CONTROL [initandlisten] git version: 888390515874a9debd1b6c5d36559ca86b44babd
mongodb_1 | 2017-06-01T15:55:52.956+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
mongodb_1 | 2017-06-01T15:55:52.956+0000 I CONTROL [initandlisten] allocator: tcmalloc
mongodb_1 | 2017-06-01T15:55:52.956+0000 I CONTROL [initandlisten] modules: none
mongodb_1 | 2017-06-01T15:55:52.956+0000 I CONTROL [initandlisten] build environment:
mongodb_1 | 2017-06-01T15:55:52.956+0000 I CONTROL [initandlisten] distmod: debian81
mongodb_1 | 2017-06-01T15:55:52.956+0000 I CONTROL [initandlisten] distarch: x86_64
mongodb_1 | 2017-06-01T15:55:52.956+0000 I CONTROL [initandlisten] target_arch: x86_64
mongodb_1 | 2017-06-01T15:55:52.956+0000 I CONTROL [initandlisten] options: {}
mongodb_1 | 2017-06-01T15:55:52.964+0000 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted
mongodb_1 | 2017-06-01T15:55:52.964+0000 I - [initandlisten] Fatal Assertion 28578 at src/mongo/util/net/listen.cpp 194
mongodb_1 | 2017-06-01T15:55:52.964+0000 I - [initandlisten]
mongodb_1 |
mongodb_1 | ***aborting after fassert() failure
mongodb_1 |
mongodb_1 |
stuff_mongodb_1 exited with code 14