I am deploying a simple GraphQL API on a server. I have port restrictions on the server. My app runs on 3000
but I wish to map it to 8117
.
I have a db.json
file in the codebase that maps the MongoDB credentials and URL to my app.js
:
{
"env": {
"MONGO_USER" : "user1",
"MONGO_PASSWORD" : "secretpassword",
"MONGO_DATABASE" : "IP_address_of_server",
"MONGO_PORT": "37017"
}
}
Upon building the Image:
docker run --name=graphql1 -p 8117:3000 my_graphql_image:1.0
I am able to expose the port on the server however upon:
docker logs -f grapqhl1
I get the following error:
{ MongooseServerSelectionError: connection timed out
at new MongooseServerSelectionError (/usr/src/app/node_modules/mongoose/lib/error/serverSelection.js:22:11)
at NativeConnection.Connection.openUri (/usr/src/app/node_modules/mongoose/lib/connection.js:808:32)
at Mongoose.connect (/usr/src/app/node_modules/mongoose/lib/index.js:333:15)
at Object.<anonymous> (/usr/src/app/app.js:56:10)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
message: 'connection timed out',
name: 'MongooseServerSelectionError',
reason:
TopologyDescription {
type: 'Single',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map { '<IP_Address>:37017' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null },
[Symbol(mongoErrorContextSymbol)]: {} }
The Mongoose client does not go into timeout when I run the container with --net=host
docker run --name=grapqhl1 -d --net=host my_graphql_image:1.0
However, since --net=host
discards Ports when using the host network mode. I am unable to reach the App via port 8117 nor the port 3000. docker ps -a
also does not show any ports to within or outside the App.
What is the optimal way to reach the API at the desired port and not run into a Connection Timeout?