I'm taking a beginner docker course (https://www.youtube.com/watch?v=3c-iBn73dDE&t=4384s), which I think is very well done.
As part of the course an app is put together with a node server and js frontend, communicating with with docker containers for mongo db and mongo express for persistence.
The node app can be found at https://gitlab.com/nanuchi/techworld-js-docker-demo-app/-/blob/master/app/server.js . containing:
MongoClient.connect("mongodb://admin:password@mongodb:27017",
function (err, client) {
if (err) throw err;
var db = client.db('user-account');
userObj['userid'] = 1;
I have the 2 docker containers running on ubuntu 20.04 on a chromebook (screenshot). When I run:
11@penguin:~/techworld-js-docker-demo-app/app$ nodejs server.js
app listening on port 3000!
but when I open a browser to localhost:3000 , I get:
(node:2716) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring pass option { useUnifiedTopology: true } to the MongoClient constructor.
/home/11/techworld-js-docker-demo-app/app/node_modules/mongodb/lib/topologies/server.js:240
throw err;
^
MongoNetworkError: failed to connect to server [mongodb:27017] on first connect [MongoNetworkError: getaddrinfo EAI_AGAIN mongodb mongodb:27017]
at Pool.<anonymous> (/home/11/techworld-js-docker-demo-app/app/node_modules/mongodb/lib/core/topologies/server.js:431:11)
at Pool.emit (events.js:198:13)
at createConnection (/home/11/techworld-js-docker-demo-app/app/node_modules/mongodb/lib/core/connection/pool.js:559:14)
at connect (/home/11/techworld-js-docker-demo-app/app/node_modules/mongodb/lib/core/connection/pool.js:973:11)
at makeConnection (/home/11/techworld-js-docker-demo-app/app/node_modules/mongodb/lib/core/connection/connect.js:39:11)
at callback (/home/11/techworld-js-docker-demo-app/app/node_modules/mongodb/lib/core/connection/connect.js:261:5)
at Socket.err (/home/11/techworld-js-docker-demo-app/app/node_modules/mongodb/lib/core/connection/connect.js:286:7)
at Object.onceWrapper (events.js:286:20)
at Socket.emit (events.js:198:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
What am I doing wrong?
Edit; just to be clear, I am running the node project on my local machine (from my ubuntu home directory) and I'm trying to connect to the docker mongo container as the backend. The author may have skipped over how she wanted to run the gitlab project (or else I misunderstood ), but I assumed she wanted to run it on the host machine. She may have planned to run it in a container, but as It was on gitlab rather than docker , I didn't know how to get the node project into a container ..