I am trying to run Gatsby with Docker Compose.
From what I understand the Gatsby site is running in my docker container.
I map port 8000 of the container to port 8000 on my localhost. 
But when looking on localhost:8000 I am not getting my gatsby site.
I use the following Dockerfile to build the image with docker build -t nxtra/gatsby .:
FROM node:8.12.0-alpine
WORKDIR /project
COPY ./package.json /project/package.json
COPY ./.entrypoint/entrypoint.sh /entrypoint.sh
RUN apk update \
  && apk add bash \
  && chmod +x /entrypoint.sh \
  && npm set progress=false \
  && npm install -g yarn gatsby-cli
EXPOSE 8000
ENTRYPOINT [ "/entrypoint.sh" ]
entrypoints.sh contains:
#!/bin/bash
yarn install
gatsby develop
docker-compose.yml ran with docker-compose up
version: '3.7'
services:
  gatsby:
    image: nxtra/gatsby
    ports:
    - "8000:8000"
    volumes:
    - ./:/project
    tty: true
docker ps shows that port 8000 is forwarded 0.0.0.0:8000->8000/tcp.
Inspecting my container with docker inspect --format='{{.Config.ExposedPorts}}' id confirms the exposure of the port ->  map[8000/tcp:{}]  
docker tops on the container shows the following processes are running in the container:
18465               root                0:00                {entrypoint.sh} /bin/bash /entrypoint.sh
18586               root                0:11                node /usr/local/bin/gatsby develop
18605               root                0:00                /usr/local/bin/node /project/node_modules/jest-worker/build/child.js
18637               root                0:00                /bin/bash
Dockerfile and docker-compose.yml are situated in the root of my Gatsby project.
My project is running correctly when I run it without docker gatsby develop.
What am I doing wrong to get the Gatsby site that runs in my container to be visible on localhost:8000?
My issue was that Gatsby was only listening to requests within the container, like this answer suggests. Make sure you've configured Gatsby for the host 0.0.0.0.  Take this (somewhat hacky) setup as an example:
Dockerfile
FROM node:alpine
RUN npm install --global gatsby-cli
docker-compose.yml
version: "3.7"
services:
  gatsby:
    build:
      context: .
      dockerfile: Dockerfile
    entrypoint: gatsby
    volumes:
      - .:/app
  develop:
    build:
      context: .
      dockerfile: Dockerfile
    command: gatsby develop -H 0.0.0.0
    ports:
      - "8000:8000"
    volumes:
      - .:/app
You can run Gatsby commands from a container:
docker-compose run gatsby info
Or run the development server:
docker-compose up develop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With