Skip to main content

GoFiber Docker Container for your Gatsby Build

Shenzhen, China

Repository

I want to use a Gatsby.js project and serve it inside a Docker container (can be pushed into a Docker cluster or to Kubernetes, OpenShift etc.). For the demonstration I will use an Gatsby MDX Starter.

Preparation

I installed the Starter with:

gatsby new gatsby_gofiber_container https://github.com/justinmahar/gatsby-starter-mdx-launchpad

And prepared a simplified variation of the GoFiber Boilerplate. To edit the Gatsby page code run:

gatsby develop

For the build I prepared an npm script that copies the static build from public to fiber/public - you can trigger the build script with:

npm run static

NOTE: that I wrote the script under Windows rimraf fiber/public && gatsby build && move public fiber - make changes, where necessary, when you are using a different OS.

Development

Once you finalized your Gatsby code run the following command to start the GoFiber and serve your static page on port 8888:

go run app.go

Go to http://localhost:8888

Prepare Deployment

We can now use the included Dockerfile to build our web app container:

docker build -t gofiber .
docker run -d -p 8888:8888 gofiber

Go to http://localhost:8888

Production Setup

Continue with NGINX Docker Ingress