Sign inSign up

afreisinger/gatsby

By afreisinger

•Updated almost 2 years ago

Gatsby Docker image with steroids

Image
0

1.2K

afreisinger/gatsby repository overview

⁠Gatsby Docker Image with steroids

To build the image:

make build

The Docker image can be found here⁠.

⁠Developing a Gatsby Site with Docker

⁠Test Site


Let’s test this out using a sample Gatsby site.

git clone https://github.com/gatsbyjs/gatsby-starter-default.git
cd gatsby-starter-default

Now launch the Docker image to serve the site.

docker run -it -p 8000:8000 -v ${PWD}:/site --name gatsby afreisinger/gatsby:latest

The -it options are not strictly required, but I find them useful because it means that I can stop the process with Ctrl-c. You also don’t need to provide a --name argument, but a named container is easier to reference (see below).

I’m using a pre-built version of the image from here⁠. You can grab the underlying code here⁠.

Visiting http://127.0.0.1:8000/⁠ yields the test site.

If you want to build a production version of the site, then pass the build command.

docker run -v ${PWD}:/site afreisinger/gatsby:latest build

The site files will be dumped to a public directory. You can then serve the site (you’ll find it at http://127.0.0.1:9000/⁠).

docker run -p 9000:9000 -v ${PWD}:/site --name gatsby afreisinger/gatsby:latest serve

⁠Debugging


First launch a container with a BASH shell.

docker run -it -v ${PWD}:/site --entrypoint /bin/bash afreisinger/gatsby:latest

That will launch a BASH shell in the container with root user.

⁠Compiling Typescript

Running the Typescript compiler will allow you to see any warnings and errors.

yarn tsc
⁠Running Tests

If there are any tests then these can also be run.

yarn test

⁠Docker Compose


Steps to Use Docker Compose

⁠Build and Run the Container with the Default Command:
docker-compose up
⁠Running Specific Commands

To run specific commands when starting the container, use docker-compose run instead of docker-compose up. Here are some examples:

Develop the Application:

docker-compose run gatsby develop

Build the Application:

docker-compose run gatsby build

Install Dependencies:

docker-compose run gatsby install

Serve the Application:

docker-compose run gatsby serve

Tag summary

Content type

Image

Digest

sha256:4fcdae50b…

Size

174.5 MB

Last updated

almost 2 years ago

docker pull afreisinger/gatsby