Dockerizing the backend
We need to do something similar for the backend Create a Dockerfile
FROM node:7.8.0
ENV NPM_CONFIG_LOGLEVEL warn
COPY . .
RUN yarn
CMD yarn start
EXPOSE 3001
It exposes port 3001.
Lets build it
docker build -t e2e-tutorial-backend .
And start it
docker run --rm -it -p 3001:3001 e2e-tutorial-backend
Aha ! you will see an error, because the backend cannot connect to mongo !
events.js:163
throw er; // Unhandled 'error' event
^
MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
at Pool.<anonymous> (/node_modules/mongodb-core/lib/topologies/server.js:328:35)
Ok, same issue as we had with the frontend trying to reach the backend. That's because each docker instance is like an isolated host. So we need to coordinate them to know each other. That where docker-compose joins us.