DEV Community

Pavel
Pavel

Posted on • Updated on

Running GatsbyJS app in Docker container

Here is an example configuration we use for testing while developing Gatsby Shopify Storefront - lightning-fast Progressive Web App (PWA) storefront for Shopify.

A Dockerfile:

FROM node:13

WORKDIR /usr/src/app

COPY package.json .

RUN yarn global add gatsby-cli

RUN yarn install

COPY gatsby-config.js .

# Optionally, copy your .env file to the container filesystem
COPY .env .

EXPOSE 8000

CMD ["gatsby", "develop", "-H", "0.0.0.0"]
Enter fullscreen mode Exit fullscreen mode

Though it is not the case with our setup, you might need to copy your project files to the container as well. Use COPY . . command for this.

Build your image:

docker build . -t gatsbystorefront:1.0.1
Enter fullscreen mode Exit fullscreen mode

Run your container:

docker run -d -p 8000:8000 --name store gatsbystorefront:1.0.1
Enter fullscreen mode Exit fullscreen mode

Though this one is short. Hope it will help, cheers! 🎅🎄

Top comments (4)

Collapse
 
anselm94 profile image
Merbin J Anselm

In particular -H 0.0.0.0 is very much required. Thanks! - stackoverflow.com/a/53195417/4486804

Collapse
 
avxkim profile image
Alexander Kim

Why are you using develop for production? It's just gatsby build and you can serve it with nginx.

Collapse
 
flq profile image
Frank Quednau

"Though it is not the case with our setup..." - alas, this is exactly the missing link for me :) I do not know how I can run the develop mode with the process running in the docker, but the Gatsby site being modifiable on my Computer...

Collapse
 
pradhumnapancholi profile image
Pradhumna Pancholi

Any particular reason for using gatsby develop instead of gatsby build?