Hot reloading of Gatsby doesn't work inside docker for Windows

Viewed 1025

I have set up Gatsby to work inside docker container and it works perfectly fine except for hot reloading.

I tried something like gatsby develop --host 0.0.0.0 --port 8080 but doesn't do hot reloading. I have to manually restart the container. Any tips would be extremely helpful. Thanks in advance.

1 Answers

In your file docker-compose you must incorporate the following environment variable:

docker-compose.yml

version: '3'

services:
  gatsby-app:
    build:
      context: ./
      dockerfile: Dockerfile
    image: gatsby-app
    container_name: gatsby-app
    working_dir: /app
    volumes:
      - /app/node_modules
      - ./app:/app
    ports:
      - 80:8000
      - 81:9000
    environment:
      - NODE_ENV=development
      - GATSBY_WEBPACK_PUBLICPATH=/
      - CHOKIDAR_USEPOLLING=1

Your DockerFile file must be:

Dockerfile

from node:latest

EXPOSE 8000

RUN npm install -g gatsby-cli yarn

WORKDIR /app

COPY ./app/package.json .

RUN yarn install && yarn cache clean

CMD ["yarn", "develop", "-H", "0.0.0.0", "-p", "8000"]


Related