Friday 2 June 2017

How can I make my nodeJS container connect with my mongoDB container?

I have 2 fairly simple Docker containers, 1 containing a NodeJS application, the other one is just a MongoDB container.

Dockerfile.nodeJS

FROM node:boron

ENV NODE_ENV production

# Create app directory
RUN mkdir -p /node/api-server
WORKDIR /node/api-server

# Install app dependencies
COPY /app-dir/package.json /node/api-server/
RUN npm install

# Bundle app source
COPY /app-dir /node/api-server

EXPOSE 3000
CMD [ "node", "." ]

Dockerfile.mongodb

FROM mongo:3.4.4

# Create database storage directory
VOLUME ["/data/db"]

# Define working directory.
WORKDIR /data

# Define default command.
CMD ["mongod"]

EXPOSE 27017

They both work independently from each other, but when I create 2 separate containers of it, they won't communicate with each other anymore (Why?). Online there are a lot of tutorials about doing it with or without docker-compose. But they all use --link. Which is a deprecated legacy feature of Docker. So I don't want to go that path. What is the way to go in 2017, to make this connection between 2 docker containers?



via user007

No comments:

Post a Comment