Gatsby Docker image with steroids
1.2K
To build the image:
make build
The Docker image can be found here.
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
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.
Running the Typescript compiler will allow you to see any warnings and errors.
yarn tsc
If there are any tests then these can also be run.
yarn test
Steps to Use Docker Compose
docker-compose up
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
Content type
Image
Digest
sha256:4fcdae50b…
Size
174.5 MB
Last updated
almost 2 years ago
docker pull afreisinger/gatsby