• Stars
    star
    313
  • Rank 133,714 (Top 3 %)
  • Language
    JavaScript
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

A reference for running a node server and create-react-app app via docker-compose.

Node + Create React App + Docker Compose

A project that runs a Node server and a create-react-app app via two separate containers, using Docker Compose.

Development

docker-compose up

For development, the server/ and client/ directories have their own docker containers, which are configured via the docker-compose.yml file.

The client server is spun up at localhost:3000 and it proxies internally to the server using the linked name as server:8080.

The local directories are mounted into the containers, so changes will reflect immediately. However, changes to package.json will likely need to a rebuild: docker-compose down && docker-compose build && docker-compose up.

Notes

Adding new scss files

In a previous version of this, you needed to restart the client for new scss files to be recognized by the watch command. This may have changed (TODO: test if this still matters with react-scripts updates):

docker-compose restart client

Installing npm dependencies

All changes to node_modules should happen inside the containers. Install any new dependencies by inside the container. You can do this via docker-compose run, but it’s easier to just upadte a running container and avoid having to rebuild everything:

docker-compose exec client

Then inside:

npm install --save <new_dependency>

Production

docker-compose -f docker-compose.prod.yml up

For production, this uses the Dockerfile at the root of the repo. It creates a static build of the client React app and runs Express inside server, which handles both the API and serving of React files.

As a result, different code is executing to serve the React files, but all of the API calls should remain the same. The difference between development and production isn’t ideal, but it does offer the simplicity of having the entire app run in one server on one machine.

This is one of multiple ways a Node + React app could be setup, as suggested here:

  • Keep them together - have Express serve both the API and React files
  • Split them apart - have Express API on one machine and the React files on another (e.g., on S3 and use CORS to access the API)
  • Put the API behind a proxy - use something like NGINX to proxy the Express API server and React static files separately

This project uses the “keep them together” approach. For better performance, you can set up a proxy (like Cloudflare) in between your server and the Internet to cache the static files. Or with some extra work you can fashion it to do either of the other two options.

Notes

Using docker compose

I have comp aliased to docker-compose on my computer.

Start via:

comp up

# or detached
comp up -d

Run a container of the server image via:

comp run server /bin/bash

Check status:

comp ps

Stop:

comp down

Run the production image:

comp -f docker-compose.prod.yml up

NOTE: if any dependencies change in package.json files, you probably will need to rebuild the container for the changes to appear, e.g.,

comp down
comp build
comp up

Setup references

References for setting up a Node project with Docker and docker-compose:

Express + React:

More Repositories

1

markdown-css

CSS for making regular HTML look like plain-text markdown.
CSS
1,430
star
2

full-page-screen-capture-chrome-extension

One-click full page screen captures in Google Chrome
JavaScript
1,310
star
3

bookmarklet

A server-side bookmarklet compiler with greasemonkey userscript-like metadata options and the power of babel and uglify
JavaScript
212
star
4

javascript-piano

An HTML5 JavaScript synth piano that generates all of its sounds using data URIs.
JavaScript
134
star
5

cssunminifier

A tool to unminify CSS—written in node.js
JavaScript
123
star
6

readmd

Pretty-print markdown
Python
32
star
7

todo-stack

Instead of a todo list, this is a todo stack—to improving multi-tasking of small daily tasks. Built on backbone.js
JavaScript
17
star
8

async-include

A super simple way to asynchronously include content on your page
JavaScript
15
star
9

static-less-coffeescript-grunt-project

A sample grunt project that compiles less and coffeescript files
JavaScript
14
star
10

picdinner_meteor

A meteor application to combine pics and audio.
JavaScript
11
star
11

original-facebook-graph-api-explorer

A tool to explore the data and options available in the graph API.
JavaScript
11
star
12

favicon-creator

Create favicons purely in Javascript
JavaScript
9
star
13

buttonmakerjs

A simple tool for generating CSS buttons.
JavaScript
8
star
14

a-muscle

Please don’t pull this repo!
7
star
15

e7n

🌎 A tool for Chrome extensions i18n/l10n to auto-populate _locales/<default_locale>/messages.json with messages from JS and HTML files
TypeScript
6
star
16

jquery-slideshow

A simple image slide show jQuery plugin
JavaScript
5
star
17

dateknight

A universal date time string formatting reference
JavaScript
4
star
18

callback-promise-async-await

Samples of callbacks, promises, and async/await usage
JavaScript
4
star
19

war-js

A JavaScript simulator of the card game war.
JavaScript
3
star
20

recursivedrawing-imageexport

User script to add an image exporting feature to recursivedrawing.com
JavaScript
3
star
21

test-chrome-extension-activetab-webrequest

This test extension uses only the `activeTab` permission and tries to access the `chrome.webRequest` API (which fails).
HTML
3
star
22

mkdjangovirtualenv

An enhancement to mkvirtualenv, specifically for django projects.
Shell
3
star
23

pinterest-api

Unoffocial API for getting a user’s pinterest pins
JavaScript
3
star
24

space-creatures

Something kind of like Space Invaders… but cuter?
JavaScript
2
star
25

emojis-json

A JSON file containing group, subgroup, character code, CLDR name, and version for all emojis (via unicode.org v12 datasets)
JavaScript
2
star
26

pseudo-cheerio

:pseudo-class support for the Cheerio NodeJS module
JavaScript
2
star
27

test-chrome-extension-capturetab

Simple example of capturing the visible tab.
JavaScript
2
star
28

expand-linkedin-bookmarklet

Bookmarklet for auto-expanding LinkedIn content
JavaScript
2
star
29

extract-garageband-midi

Extra the MIDI file from a GarageBand loop
Python
2
star
30

raphael-reference-css

Chrome user script to make the Raphael.js reference page TOC more useful.
JavaScript
2
star
31

test-chrome-extension-downloadrecents

Chrome extension test of “Save As” with download and defaulting to the recent save as directory
HTML
2
star
32

emoji-image-generator

An experiment in bulk-creating images of emojis in the browser.
JavaScript
2
star
33

test-chrome-extension-sandbox

Test to trigger settimeout not working in messages for an extension content script on content security policy sandbox pages
JavaScript
1
star
34

test-chrome-extension-executeiframes

Test `executeScript` with `allFrames: true`.
JavaScript
1
star
35

pxl-treats

a simple rust “game” to feed treats to a hungry pixel
Rust
1
star
36

dynamodb-full-scan

Helpers for doing full paginated scan operations as a Promise or AsyncGenerator with the "asw-sdk" DynamoDB DocumentClient.
TypeScript
1
star
37

videoloop

An experiment with delay and looping of video
JavaScript
1
star
38

jacobs-css3-ladder

JavaScript
1
star
39

todo-stack_meteor

A micro-task manager for keeping track of things as they stack up throughout the day—written in Meteor.
JavaScript
1
star
40

langtons-ant

A JavaScript implementation of Langton’s ant
JavaScript
1
star
41

e7n-aws-translate

🌍 A script for loading Chrome extension messages.json files and generating translations.
TypeScript
1
star