RAJA ONCE AGAIN
RAJA ONCE AGAIN

Reputation: 51

Docker build failed ERR CONREFUSSED, MERN

The application is built on MERN stack, ReactJS , Node and MongoDB I have created a docker which is running fine but runs only the front end and throws this error, Can't figure out where I am doing wring

The error I get is

 Proxy error: Could not proxy request /api/category/ from localhost:3000 to http://localhost:5001/.
myapp-react-client | See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).

this is my docker compose file

version: "3.7"

services:
  server:
    build:
      context: ./
      dockerfile: Dockerfile
    image: myapp-server
    container_name: myapp-node-server
    command: npm run dev
    volumes:
      - ./:/usr/src/app
      - /usr/src/app/node_modules
    ports:
      - "5001:5001"
    depends_on:
      - mongo
    env_file: ./config/config.env
    environment:
      - NODE_ENV=development
    networks:
      - app-network
  mongo:
    image: mongo
    volumes:
      - data-volume:/data/db
    ports:
      - "27017:27017"
    networks:
      - app-network

  client:
    build:
      context: ./client
      dockerfile: Dockerfile
    image: myapp-client
    container_name: myapp-react-client
    stdin_open: true
    tty: true
    volumes:
      - ./client/:/usr/app
      - /usr/app/node_modules
    depends_on:
      - server
    ports:
      - "3000:3000"
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  data-volume:
  node_modules:
  web-root:
    driver: local

This is my package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "axios": "^0.19.2",
    "chart.js": "^2.9.4",
    "dateformat": "^4.4.2",
    "owl.carousel": "^2.3.4",
    "react": "^16.13.1",
    "react-chartjs-2": "^2.11.1",
    "react-dom": "^16.13.1",
    "react-infinite-scroll-component": "^5.1.0",
    "react-owl-carousel": "^2.3.3",
    "react-redux": "^7.2.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.4.1",
    "redux": "^4.0.5",
    "redux-thunk": "^2.3.0",
    "uuid": "^7.0.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "proxy": "http://localhost:5001/"
}

A little help is also appreciated,

Upvotes: 0

Views: 150

Answers (1)

Arib Yousuf
Arib Yousuf

Reputation: 1285

Change your proxy value from "http://localhost:5001/" to "http://server:5001/" in package.json. The "server" is the name of your backend service. In Docker, your containers are running inside a Docker Network, so, they can't access your localhost at the host machine.

Upvotes: 2

Related Questions