(no title)
fckthisguy | 2 years ago
We needed to set env vars on React applications (the frontend) inside Docker containers. The containers were going to be built in CI/CD, and we didn't want different builds for each environment.
We solved this by adding a small JS script that is included in the base HTML. It pushes env vars into the window object, so they're accessible from window.env.
The JS file is generated by a Bash script that's ran whenever the container starts (by modifying the entry-point.sh file used by Nginx's Docker image).
The Bash script loads enumerates any environment variable with a given prefix.
Docker already allows you to set runtime environment variables from the run command, or via Docker Compose.
Im the end, the developer experience comes down to "docker run image:tag -e PREFIX_FOO=BAR".
No comments yet.