I am using Gatsby v5 and i am trying to setup docker installation for Gatsby so that i can containerize it and start using it. My folder structure is as below;
main-folder
|_ backend (docker is setup and running as expected)
|_ frontend (trying to setup docker for this)
I have created two files in frontend
directory
- Dockerfile
- docker-compose.yml
My contents for Dockerfile
are as below
FROM node:20.11.1-alpine as node
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install -g gatsby-cli
RUN npm install
COPY . .
My contents for docker-compose
are as below
version: "3.9"
services:
node:
build: .
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
command: gatsby develop -H 0.0.0.0
ports:
- "9000:9000"
tty: true
when i run docker compose up
i get an output in my terminal saying as below
You can now view main-folder in the browser.
node-1 | ⠀
node-1 | Local: http://localhost:8000/
node-1 | On Your Network: http://172.18.0.2:8000/
node-1 | ⠀
node-1 | View GraphiQL, an in-browser IDE, to explore your site's data and schema
node-1 | ⠀
node-1 | Local: http://localhost:8000/___graphql
node-1 | On Your Network: http://172.18.0.2:8000/___graphql
When i try to access http://localhost:8000/
no luck but when i access http://172.18.0.2:8000/
i can see my app up and running
I am unable to understand why am i unable to access http://localhost:8000/
, i did docker compose logs but, no errors also i tried to inspect what could possibly be wrong but unable to get to a root cause, i want this to be accessible on http://localhost:<custom-port>/
but the moment i do some changes in the docker-compose,yml
it compiles and shows me a message
You can now view main-folder in the browser.
node-1 | ⠀
node-1 | Local: http://localhost:8000/
node-1 | ⠀
node-1 | View GraphiQL, an in-browser IDE, to explore your site's data and schema
node-1 | ⠀
node-1 | Local: http://localhost:8000/___graphql
but, i cannot access anything on http://localhost:8000/
, it’s like its never there.
Also i wanted to replace gatsby develop
with npm start
but the moment i do it again it gains the same loop where build develops and runs