Open ghettosamson opened 4 years ago
I think your problem is because you are only opening port 3000, can you try changing EXPOSE 3000
to EXPOSE 3000 27017 27018 27019
see if that does the trick.
I updated the run command to bind ports 27017, 27018, 27019 and also the EXPOSE directive in the Dockerfile but I still get the connection refused.
I got mine running, try the following when you run the container:
docker run -ti -p 27017-27019:27017-27019 --network="host" --name mongo-runrs YOURIMAGEID
If you don't define --network="host"
then you won't be able to connect to the container using localhost.
Hope this helps.
I still get the same error. Note that when we use "host" network mode the published ports are discarded.
docker run -it -p 27017-27019 --network="host" --name my-api --env-file RS.env my-api
WARNING: Published ports are discarded when using host network mode
> my-api@0.2.21 start /src
> node --inspect server
Debugger listening on ws://127.0.0.1:9229/fe5f0b84-faa4-40eb-bb0f-037ccb27f3fd
For help, see: https://nodejs.org/en/docs/inspector
debug: Mongoose connecting to mongodb://localhost:27017,localhost:27018,localhost:27019/my-db?replicaSet=rs with options {"useCreateIndex":true,"useNewUrlParser":true,"useUnifiedTopology":true,"useFindAndModify":false,"timestamp":"2020-10-27T12:06:34.295Z"}
info: Request logging set to: false {"timestamp":"2020-10-27T12:06:34.414Z"}
info: MY API Express app starting on port 3000 with log level silly {"timestamp":"2020-10-27T12:06:34.415Z"}
error: UnhandledRejection Error: connect ECONNREFUSED 127.0.0.1:27017 {"timestamp":"2020-10-27T12:07:04.311Z"}
error: connect ECONNREFUSED 127.0.0.1:27017 {"reason":{"type":"ReplicaSetNoPrimary","setName":"rs","maxSetVersion":1,"maxElectionId":"7fffffff00000000000000a5","servers":{},"stale":false,"compatible":true,"compatibilityError":null,"logicalSessionTimeoutMinutes":null,"heartbeatFrequencyMS":10000,"localThresholdMS":15,"commonWireVersion":7}}
I'm facing the same issue, where client is disconnected arbitrarily saying MongooseServerSelectionError: connection timeout.
Environment: MacOS Issue: I have a NodeJS application that I want to run inside a Docker container to connect to the replica set using mongoose 5.10.6. I start my replica set with
run-rs --dbpath ./data --keep
. When I run my application outside of a Docker containernode server
I connect successfully{"message":"Mongoose successfully connected to mongodb://localhost:27017,localhost:27018,localhost:27019/my-app-dev?replicaSet=rs","level":"info","service”:"my-ap"
However, when I run the application inside of a Docker container, I get the following errorHere is my Dockerfile