I have a problem on linking 2 containers in development environment with Docker.
I have already my mongo container running calls db.
Here my Dockerfile for my Node app :
FROM nodesource/node:4.0
ADD package.json package.json
RUN npm install
ADD . .
ENV NODE_ENV development
CMD ["node","server.js"]
After building the the image I run it inside a linking container with the following command :
docker run --name myapp --link db:db_1 -p 80:3000 -d myapp
Here my two containers :
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES 216304df0905 myapp "node server.js"
25 minutes ago Exited (1) 13 minutes ago
myapp 506f9fcfd30b mongo "/entrypoint.sh mongo"
19 hours ago Up 19 hours 27017/tcp db
myapp logs :
development
Server running at http://localhost:3000
/usr/src/app/node_modules/mongoose/node_modules/mongodb/lib/server.js:242 process.nextTick(function() { throw err; }) ^ Error: connect ECONNREFUSED 127.0.0.1:27017 at Object.exports._errnoException (util.js:837:11) at exports._exceptionWithHostPort (util.js:860:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1060:14)
It seems that the connection between my app and mongo doesn't work.
Someone can help me to deal with that ?
db_1
as the hostname when connecting to the mongodb, when you are using linked containers. – JAM