0

I have three services starting up from my docker-compose.yml file. A React frontend, a node js backend and a mongodb service. It starts up and run absolutely fine on windows but it takes lots of time on mac that most of the time it throws http timeout error.

My docker-compose file -

version: "2"
services:
  client:
    build:
      context: ./react-ui
      args:
        NPM_TOKEN: $NPM_TOKEN
    environment:
      - CHOKIDAR_USEPOLLING=true
      - NPM_TOKEN=${NPM_TOKEN}
    ports:
      - "3001:3001"
    volumes:
      - /app/node_modules
      - ./react-ui:/app
  server:
    command: yarn dev -- -L
    build:
      context: ./server
    restart: always
    environment:
      - CHOKIDAR_USEPOLLING=true
      - NODE_ENV=development
      - MONGODB_URI=mongodb://mongodb:27017/react-node-project
    ports:
      - "3000:3000"
    volumes:
      - /app/node_modules
      - ./server:/app
    depends_on:
      - mongodb
  mongodb:
    image: mongo
    ports:
      - "27017:27017"

My react dockerfile -

FROM node:alpine

ARG NPM_TOKEN

ENV NPM_TOKEN=${NPM_TOKEN}

WORKDIR "/app"
COPY ./package.json ./
COPY ./.npmrc . 
RUN  yarn install
COPY . .
CMD ["yarn", "start"]

My server dockerfile -

FROM node:8.11

EXPOSE 3000

ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

WORKDIR /app
COPY ./package.json .
RUN yarn install
COPY . .

CMD ["yarn", "docker:start"]

docker:start script does nodemon ./src/index.js

I have made sure to add node_modules in my .dockerignore file. Also the client service specifically is taking lots of time for mac. Maybe I have written something incorrectly there which is taking so much time.

I have tried on 2-3 mac machines, the behaviour is same.

Atin Singh
  • 3,624
  • 2
  • 18
  • 25
  • 1
    Host-directory bind mounts on Docker for Mac are [known to be slow](https://docs.docker.com/docker-for-mac/osxfs/#performance-issues-solutions-and-roadmap). If you delete all of your `volumes:` blocks, you will run the code that you're actually building into your images (so much more reproducible at deployment time), you'll avoid problems with Docker ignoring changes in your `package.json` file, and you won't have this performance issue. – David Maze Mar 18 '20 at 11:11
  • @DavidMaze That does solve to problem to some extent but because I removed the volumes bind hot reloading just stops working. – Atin Singh Mar 20 '20 at 14:03
  • You can use a local Node installation for that (`brew install node`). – David Maze Mar 20 '20 at 14:48
  • @DavidMaze Sorry for such a late reply. But i am using Create react app and removing volumes breaks hot reloading. I didn't get what you are suggesting. Should I add a command in my dockerfile `RUN brew install node`? – Atin Singh Apr 09 '20 at 13:43
  • I'm suggesting not using Docker at all here. In your host non-Docker CRA development environment, you can [set it up to proxy the backend application](https://create-react-app.dev/docs/proxying-api-requests-in-development) pointing at the published `ports:` of your Docker `server` container. – David Maze Apr 09 '20 at 14:22
  • @DavidMaze Having the whole app (frontend & backend) in docker environment is a requirement. I can't keep it non-docker. – Atin Singh Apr 09 '20 at 15:15

0 Answers0