when I run it alone or together, there are no errors in my frontend and backend parts and they work as I want.and now I want to use docker, but when I try a error appears. I tried to solve with a previous solution that wrote before, but doesn't work., I create my Docker file and I type "docker build ." and this works
then
I type docker run Image Id
Error
PS D:\javascript_projects\nimble_dersleri\backend> docker run 880a0a3e9b21
> ders-6@1.0.0 start
> node .bin/www
(node:18) [DEP0128] DeprecationWarning: Invalid 'main' field in '/package.json' of 'service.js'. Please either fix that or report it to the module author
(Use `node --trace-deprecation ...` to show where the warning was created)
started listening on 3000
connection error MongooseServerSelectionError: getaddrinfo EAI_AGAIN db
at Connection.openUri (/node_modules/mongoose/lib/connection.js:819:32)
at /node_modules/mongoose/lib/index.js:378:10
at /node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/node_modules/mongoose/lib/index.js:1223:10)
at Mongoose.connect (/node_modules/mongoose/lib/index.js:377:20)
at Object.<anonymous> (/routes/mongo-connection.js:7:10)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) { 'db:27017' => [ServerDescription] },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
logicalSessionTimeoutMinutes: undefined
},
code: undefined
}
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^
MongooseServerSelectionError: getaddrinfo EAI_AGAIN db
at Connection.openUri (/node_modules/mongoose/lib/connection.js:819:32)
at /node_modules/mongoose/lib/index.js:378:10
at /node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/node_modules/mongoose/lib/index.js:1223:10)
at Mongoose.connect (/node_modules/mongoose/lib/index.js:377:20)
at Object.<anonymous> (/routes/mongo-connection.js:7:10)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1174:10) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) {
'db:27017' => ServerDescription {
address: 'db:27017',
passives: [],
arbiters: [],
tags: {},
minWireVersion: 0,
maxWireVersion: 0,
roundTripTime: -1,
lastUpdateTime: 1358575,
lastWriteDate: 0,
error: MongoNetworkError: getaddrinfo EAI_AGAIN db
at connectionFailureError (/node_modules/mongodb/lib/cmap/connect.js:382:20)
at Socket.<anonymous> (/node_modules/mongodb/lib/cmap/connect.js:302:22)
at Object.onceWrapper (node:events:628:26)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[Symbol(errorLabels)]: Set(0) {}
}
}
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
logicalSessionTimeoutMinutes: undefined
},
code: undefined
}
Node.js v18.6.0
mongo-connection
const mongoose = require('mongoose');
var db = mongoose.connection
mongoose.connect('mongodb://db:27017/week6');
db.on('error', console.error.bind(console,'connection error'))
db.once('open',function(){
console.log('we are connected to mongodb!')
})
Dockerfile
FROM node:18.6-alpine3.15
COPY . .
RUN npm install
CMD ["npm", "start"]