Injecting Environment Variables with Docker into Static Webpages

submited by
Style Pass
2023-03-17 07:30:03

When building a microserivce frontend it might be necessary to inject configuration parameters into the Docker container, which then are printed into a static website or even a javascript file. Many web servers, such as nginx and apache, support Server Side Includes (SSI). SSI is an old server-side web-technology, which was around for decades. SSI could be used for injecting environment variables into static websites. A full example can be found in a corresponding Github Repository.

SSI provides a set of directives, which can be embedded in any document served by a web server. The web server can be configured to preprocess the document and also process the directives. For the stated use case the echo directive could be used. This directive can print a variable, known to the web server, into a served document.

Assume that for the web server a variable ENV_MY_NAME is configured and the SSI module is activated. Then with the following echo directive, the variable is printed into the HTML document:

Leave a Comment