• Stars
    star
    358
  • Rank 114,471 (Top 3 %)
  • Language
    Shell
  • License
    MIT License
  • Created almost 9 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Docker image that builds and hosts a Gatsby site

gatsbyjs/gatsby-docker Travis CI Build Status

Docker image that builds and hosts a Gatsby site.

Note: this is a community maintained project and doesn't yet have support for Gatsby v3 and beyond features like Functions, SSR, and DSG

This image has two major tags:

  1. latest - will serve your assets on production using up an nginx server

  2. onbuild - builds your project and creates a new docker image

Usage

  1. Create at the root of your project a Dockerfile and .dockerignore, as below: Dockerfile
    FROM gatsbyjs/gatsby:onbuild as build
    
    FROM gatsbyjs/gatsby
    COPY --from=build /app/public /pub
    .dockerignore
    .cache/
    node_modules/
    public/

    The first image is going to copy your project, install dependencies and build it.

  2. Build your project's docker image:
    docker build -t myproject/website .
  3. Upload to the registry
    docker push myproject/website
  4. Use it
    docker run --rm -p 80:80 myproject/website
    # Open your browser at http://localhost

Configuration

The way Nginx behaves can be configured using environment variables.

Please refer to the docker run command options for the --env-file flag where you can specify all required environment variables in a single file. This will save you from writing a potentially long docker run command. Alternatively you can use docker-compose.

Below is the complete list of available options that can be used to customize your Nginx configuration:

Environment variable Default Description
CACHE_IGNORE html Regular expression to specify which paths shouldn't be cacheable (header Cache-Control set to no-store).
CACHE_PUBLIC ico|jpg|jpeg|png|gif|svg|js|jsx|css|less|swf|eot|ttf|otf|woff|woff2 Regular expression to specify which paths should be cacheable (headers Cache-Control set to public and Expires set to the value of $CACHE_PUBLIC_EXPIRATION).
CACHE_PUBLIC_EXPIRATION 1y Time to set for header Expires. See http://nginx.org/en/docs/http/ngx_http_headers_module.html#expires
CHARSET utf-8 Charset being used in Content-Type response header field. See http://nginx.org/en/docs/http/ngx_http_charset_module.html
CUSTOM_SERVER_CONFIG Need to add some advanced/custom nginx config? No problem, you can inject through this environment variable. NOTE: would be discarded if /etc/nginx/server.conf is present.
DEBUG false If set to true the configuration is being printed before the server starts.
GZIP_LEVEL 6 Gzip compression level of a response. See http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_comp_level
GZIP_TYPES application/javascript application/x-javascript application/rss+xml text/javascript text/css image/svg+xml MIME types in addition to text/html for which gzip compression should be enabled. See http://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_types
HTTP_PORT 80 The address and / or port for IP, or the path for a UNIX-domain socket on which the server will accept requests. See http://nginx.org/en/docs/http/ngx_http_core_module.html#listen
PUBLIC_PATH /pub The path to the directory from which files are being served. See http://nginx.org/en/docs/http/ngx_http_core_module.html#root
TRAILING_SLASH true Specifies if paths should end with a trailing slash or not. Prevents duplicated content by redirecting requests to URLs ending with a slash to its non-trailing-slash equivalent if set to true and the other way around for false.
WORKER_CONNECTIONS 1024 The maximum number of simultaneous connections that can be opened by a worker process. See http://nginx.org/en/docs/ngx_core_module.html#worker_connections
DISABLE_FILE_CACHE false Disables nginx's open file cache for when used with a network storage (NFS, SMB, etc)

Append rules for the server block in nginx config

You can mount a file to /etc/nginx/server.conf to extend the server block in nginx config. This could be useful if you have defined client-only routes in GatsbyJS. For example for client only rules on path /client-only the content of your mounted file should be like:

rewrite ^/client-only/([^.]*?/)$ /client-only/index.html;

Alternatively you can use a custom Dockerfile and copy the file on build:

FROM gatsbyjs/gatsby:latest
COPY nginx-server-rules.conf /etc/nginx/server.conf

NOTE: By adding the file /etc/nginx/server.conf, all the contents of the CUSTOM_SERVER_CONFIG environment variable will be discarded.

More Repositories

1

gatsby

The best React-based framework with performance, scalability and security built in.
JavaScript
54,936
star
2

gatsby-starter-blog

Gatsby starter for creating a blog
JavaScript
3,487
star
3

gatsby-starter-default

The default Gatsby starter
JavaScript
1,389
star
4

gatsby-starter-hello-world

Starter with the bare essentials needed for a Gatsby site
JavaScript
639
star
5

store.gatsbyjs.org

The Gatsby store for swag and other Gatsby goodies.
JavaScript
603
star
6

gatsby-source-wordpress-experimental

The upcoming v4 of gatsby-source-wordpress, currently in beta
JavaScript
384
star
7

gatsby-starter-shopify

A Gatsby starter using the latest Shopify plugin showcasing a store with product overview, individual product pages, and a cart
JavaScript
288
star
8

desktop

TypeScript
222
star
9

wp-gatsby

WordPress plugin for gatsby-source-wordpress
PHP
163
star
10

gatsby-ja

Japanese translation of Gatsbyjs.org
JavaScript
151
star
11

gatsby-pt-BR

Brazilian Portuguese translation of Gatsbyjs.org
JavaScript
150
star
12

themes

This is a repo for Gatsby's official themes.
JavaScript
141
star
13

gatsby-starter-blog-theme

Starter for using the official gatsby blog theme
JavaScript
121
star
14

gatsby-starter-wordpress-blog

CSS
105
star
15

rfcs

RFCs for changes to Gatsby
85
star
16

gatsby-graphql-toolkit

TypeScript
79
star
17

gatsby-source-shopify

TypeScript
67
star
18

gatsby-starter-documentation

This starter is for Gatsby v0 and is not maintained
JavaScript
67
star
19

gatsby-starter-wordpress-homepage

JavaScript
63
star
20

gatsby-starter-theme-workspace

JavaScript
62
star
21

gatsby-starter-contentful-homepage

JavaScript
53
star
22

gatsby-starter-theme

A Gatsby theme starter using the official blog theme, and the official notes theme
JavaScript
52
star
23

api.gatsbyjs.org

The API for the Gatsby swag store.
JavaScript
47
star
24

tutorial-example

The example project built by following the Gatsby Tutorial: https://gatsbyjs.com/docs/tutorial/
JavaScript
45
star
25

gatsby-es

Gatsby documentation in Spanish
JavaScript
41
star
26

gatsby-starter-kontent-ai-homepage

JavaScript
39
star
27

gatsby-id

Indonesian translation of Gatsbyjs.org
JavaScript
36
star
28

gatsby-starter-kontent-ai-homepage-ts

TypeScript
34
star
29

gatsby-starter-landing-page

Create custom landing pages using Gatsby and Contentful
JavaScript
34
star
30

gatsby-ko

Korean translation of Gatsbyjs.org
JavaScript
30
star
31

mdx-deck-theme

The theme we use for Gatsby-related slide decks powered by `mdx-deck`
HTML
27
star
32

gatsby-starter-minimal

JavaScript
26
star
33

gatsby-starter-notes-theme

Starter for using the official gatsby notes theme
JavaScript
20
star
34

gatsby-starter-drupal-homepage

JavaScript
20
star
35

gatsby-ru

Gatsby documentation in Russian
JavaScript
20
star
36

gatsby-zh-Hans

Simplified Chinese translation of Gatsbyjs.org
JavaScript
19
star
37

gatsby-fr

French translation of Gatsbyjs.org
JavaScript
19
star
38

homepage-starters

Development setup for homepage starters with multiple CMS backends
JavaScript
18
star
39

gatsby-starter-datocms-homepage

JavaScript
16
star
40

gatsby-functions-beta

A showcase of Gatsby Functions for the public beta
JavaScript
15
star
41

gatsby-starter-kitchen-sink

This starter is for Gatsby v0 and is not maintained
JavaScript
13
star
42

peril-gatsbyjs

This repo houses the settings for Peril.
TypeScript
13
star
43

gatsby-starter-sanity-homepage

Create a homepage with Gatsby and Sanity
JavaScript
11
star
44

themejam.gatsbyjs.org

Website for the Gatsby Theme Jam
JavaScript
11
star
45

gatsby-starter-blog-theme-core

JavaScript
10
star
46

react-18-ecommerce-demo

gatsby-starter-shopify with react 18 features
JavaScript
9
star
47

gatsby-starter-contentful-homepage-ts

TypeScript
9
star
48

gatsby-pl

Polish translation of Gatsbyjs.org
JavaScript
9
star
49

gatsby-starter-minimal-ts

TypeScript
9
star
50

gatsby-ar

Arabic translation of Gatsbyjs.org
JavaScript
8
star
51

gatsby-hi

Hindi translation of Gatsbyjs.org
JavaScript
8
star
52

gatsby-starter-plugin

JavaScript
8
star
53

gatsby-starter-rendering-modes

An example starter using new rendering modes in Gatsby 4
JavaScript
7
star
54

gatsby-it

Italian translation of Gatsbyjs.org
JavaScript
7
star
55

gatsby-bn

Bengali translation of Gatsbyjs.org
JavaScript
7
star
56

gatsby-starter-sanity-homepage-ts

Create a homepage with Gatsby and Sanity
TypeScript
7
star
57

gatsby-tr

Turkish translation of Gatsbyjs.org
JavaScript
7
star
58

gatsby-i18n-source

Source repo for gatsbyjs.org translation
JavaScript
6
star
59

gatsby-starter-wordpress-homepage-ts

TypeScript
6
star
60

gatsby-web-creators

A repository of live coding examples from the Gatsby Web Creators livestream series
HTML
5
star
61

gatsby-partial-hydration-starter

Example on how to implement partial hydration in Gatsby
JavaScript
5
star
62

gatsby-de

German translation of Gatsbyjs.org
JavaScript
4
star
63

gatsby-starter-slices

A starter showcasing Gatsby 5 and Slices
JavaScript
4
star
64

gatsby-starter-mdx-basic

This functionality is now built into Gatsby. Run `npm init gatsby` from the command line and choose MDX as the data source to get started.
CSS
4
star
65

webinar-using-mdx

Sample repository implementing MDX pages in a new Gatsby site
CSS
4
star
66

gatsby-zh-Hant

Traditional Chinese translation of Gatsbyjs.org
JavaScript
3
star
67

gatsby-fi

Finnish translation of Gatsbyjs.org
JavaScript
3
star
68

gatsby-provision-contentful

Provision Contentful Content for your Gatsby site
JavaScript
3
star
69

will-it-generate

A utility to generate benchmark data of varying sizes with similar complexity
JavaScript
3
star
70

vscode-extension

Experimental vscode extension to improve your Gatsby experience
TypeScript
2
star
71

gatsby-vi

Vietnamese translation of Gatsbyjs.org
JavaScript
2
star
72

gatsby-starter-drupal-homepage-ts

TypeScript
2
star
73

gatsby-nl

Dutch translation of Gatsbyjs.org
JavaScript
2
star
74

gatsby-mn

Mongolian translation of Gatsbyjs.org
JavaScript
1
star
75

gatsby-en

(THIS IS A TEST REPOSITORY) English translation of Gatsbyjs.org
1
star
76

gatsby-dev-sites-proxy

Proxies sites built for PRs from their S3 bucket
JavaScript
1
star
77

gatsby-starter-datocms-homepage-ts

TypeScript
1
star
78

gatsby-fa

Persian translation of Gatsbyjs.org
JavaScript
1
star
79

gatsby-ca

Catalan translation of Gatsbyjs.org
JavaScript
1
star