Can’t connect other services when running docker image that is built from Dockerfile

  docker, docker-compose, dockerfile

I have a node project which uses Redis for queue purposes.
I required the Redis in compose file & it’s working fine. But when I try to build the docker image from the Dickerfile and run that built image with docker run, it can’t find/connect to the Redis.
My question is: If docker doesn’t include the images from the compose file when building the image from Dockerfile, how the built image can run?

Compose & Dockerfile are given below.

version: '3'
services:
  oaq-web:
    image: node:16.10-alpine3.13
    container_name: oaq-web
    volumes:
      - ./:/usr/src/oaq
    networks:
      - oaq-network
    working_dir: /usr/src/oaq
    ports:
      - "5000:5000"
    command: npm run dev
  redis:
    image: redis:6.2
    ports:
      - "6379:6379"
    networks:
      - oaq-network
networks:
  oaq-network:
    driver: bridge
FROM node:16.10-alpine3.13

RUN mkdir -p app

COPY . /app

WORKDIR /app

RUN npm install

RUN npm run build
CMD ["npm", "start"]

Source: Docker Questions

LEAVE A COMMENT