Skip to content

vimaire/docker-spa-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

This repository is an exemple of dockerizing a web application and using the same image against different backends (dev, staging, prod). This means the image must be able to take in environment variables and make the web application use it.

This exemple is illustrated by using the "create-react-app" with a custom message.

For enterprise use cases, think about configuration file containing api urls.

Instructions

  1. pull this repository
  2. run the following command
docker run -p 3000:80 -e "CFG_MESSAGE=Hello docker" --rm -it  $(docker build -q .)
  1. open your browser on port 3000 and see the message "Hello docker" on the main page

How it works

SPA Side

We added a static js file "configuration.js" writing configuration data to the environment (here it's in the window object but you can put it anywhere you like).

in the "App" component, on the render method, we used window.__configuration__.message field.

Server side

The server has two main functions :

  • Generating dynamically the configuration file at startup. (for more instructions, see read-env npm package)
  • Serving the static files

About

Example on how to set configuration of a dockerized web application with environment variables

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published