I'm trying to dockerize an existing app using Angular for the frontend, node.js as a backend and Postgres as DB. I've created a network and tried to run the containers one by one without the DB for now but I get an error with the node.js backend.
I've built the backend image with this Dockerfile:
FROM node:10.17.0-alpine
WORKDIR /app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE 3000
CMD node --experimental-worker backend.js
and the frontend one with this:
FROM node:10.17
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install -yq google-chrome-stable
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/package.json
RUN npm install
RUN npm install -g @angular/[email protected]
COPY . /app
EXPOSE 4200
CMD ng serve --host 0.0.0.0
I've built the images and I've started the containers with:
docker container run --network my-network -it -p 4200:4200 frontend
docker container run --network my-network -it -p 3000:3000 backend
docker container run --network my-network -it --name my-redis -p 6379:6379 redis
but the backend relies on redis to start so it fails with the error:
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
I've tried:
docker container run --network my-network --link my-redis:redis -it -p 3000:3000
but it doesn't help at all. I'm sorry but I am very new to Docker so any clarification would be useful.