maasha
November 22, 2018, 5:35pm
1
I have build a docker image using meteor-lauchpad (fabulous tool). The docker image works just fine with the local Mongodb. But I have problems with docker-compose, which results in errors of the type:
MongoNetworkError: failed to connect to server [mongo:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 172.21.0.3:27017]
If I use the local Mongodb (by not providing a MONGO_URL
) then the app works fine.
Here is the docker-compose.yml
file:
version: '3.1'
services:
meteor:
image: maasha/meteor-react-app:latest
restart: always
env_file:
- meteor.env
links:
- mongo
ports:
- 4000:3000
mongo:
image: mongo:latest
restart: always
# volumes:
# - ./data:/data/db
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
And the meteor.env
file:
MONGO_URL=mongodb://root:example@mongo:27017/meteor
Suggestions?
Hey friend,
Here is my docker-compose, it works fine:
version: "3"
services:
app:
container_name: testeapp-meteor
restart: always
volumes:
- .:/home/meteor/app/
build: .
ports:
- "3000:3000"
links:
- mongo
mongo:
container_name: testeapp-mongo
image: mongo
volumes:
- ../mongoDB/testapp:/data/db
ports:
- "27017:27017"
I though it would be a link problem, but it seems your file is ok.
local mongo and mongo container are using different ports?
I had problem using this:
MONGO_URL=mongodb://root:example@mongo:27017/meteor
It was a bug documented in Stack Overvlow. I will search the link and post here.
maasha
November 23, 2018, 8:39am
3
Thanks,
Ad 2. I am not interested in using the local mongo, but want meteor to connect to the one in the mongo container - however that is done …
maasha
November 23, 2018, 8:49am
4
I suspect I need to setup stuff on the MongoDB to initialize database, user and password?
maasha:
ports: - 27017:27017
I asked about the local mongo because they are probably using the same port. Therefore the mongo container would crash and the link would not work
maasha
November 23, 2018, 12:25pm
7
Hm, I get a [MongoNetworkError: connect ECONNREFUSED 172.25.0.2:27018]
from the meteor app, so the database is there and can be reached (I did compile an image without local mongo and get the same error)? What do I need to setup in the mongo container? I see nothing in it’s config:
mongo:
image: mongo:latest
restart: always
# volumes:
# - ./data:/data/db
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
That ensures the existence of the last /meteor
in MONGO_URL=mongodb://root:example@mongo:27018/meteor
maasha
November 23, 2018, 2:06pm
8
Progess. Now I get this:
meteor_1 | MongoError: Authentication failed.
meteor_1 | at /opt/meteor/dist/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/pool.js:581:63
meteor_1 | at authenticateStragglers (/opt/meteor/dist/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/pool.js:504:16)
meteor_1 | at Connection.messageHandler (/opt/meteor/dist/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/pool.js:540:5)
meteor_1 | at emitMessageHandler (/opt/meteor/dist/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connection.js:310:10)
meteor_1 | at Socket.<anonymous> (/opt/meteor/dist/bundle/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/connection.js:453:17)
meteor_1 | at emitOne (events.js:116:13)
meteor_1 | at Socket.emit (events.js:211:7)
meteor_1 | at addChunk (_stream_readable.js:263:12)
meteor_1 | at readableAddChunk (_stream_readable.js:250:11)
meteor_1 | at Socket.Readable.push (_stream_readable.js:208:10)
meteor_1 | at TCP.onread (net.js:594:20)
meteor_1 | => Starting app on port 3000...
mongo_1 | 2018-11-23T14:04:26.593+0000 I NETWORK [listener] connection accepted from 172.28.0.4:46278 #17 (5 connections now open)
mongo_1 | 2018-11-23T14:04:26.602+0000 I NETWORK [conn17] received client metadata from 172.28.0.4:46278 conn17: { driver: { name: "nodejs", version: "3.1.6" }, os: { type: "Linux", name: "linux", architecture: "x64", version: "4.9.93-linuxkit-aufs" }, platform: "Node.js v8.9.0, LE, mongodb-core: 3.1.5" }
mongo_1 | 2018-11-23T14:04:26.603+0000 I ACCESS [conn17] Supported SASL mechanisms requested for unknown user 'root@meteor'
mongo_1 | 2018-11-23T14:04:26.617+0000 I ACCESS [conn17] SASL SCRAM-SHA-1 authentication failed for root on meteor from client 172.28.0.4:46278 ; UserNotFound: Could not find user root@meteor
mongo_1 | 2018-11-23T14:04:26.622+0000 I NETWORK [conn17] end connection 172.28.0.4:46278 (4 connections now open)
Now I need a way to create the root@meteor user in the mongo container
maasha:
app on port
Are you sure your container is not using the same port as the local mongo? Local mongo is down?
Just for testing, try without credentials, on the docker-compose and clear the Mongo_URL on meteor
It’s been a long time since the last answer but i believe the solution is add “/meteor?authSource=admin” in the end of url
"mongodb://root:password@<IP>:<PORT>/meteor?authSource=admin"