DEV Community

Markus Huggler for Novaloop Ltd

Posted on • Updated on

One Docker Image to Rule them All

We have a website with multiple divisions. We want to reuse the same docker image for all the divisions.

First approach was to load the configuration dynamically from a server (depending on the ENV variables in the image). This would mean that every client will have to send the request and that the configuration server's uptime is crucial.

We are now using variables in the environment.ts file, eg:

export const environment = {
  url: 'https://__DOMAIN__',
Enter fullscreen mode Exit fullscreen mode

We then have an script for the docker which can be called with arguments and replaces the strings in the application.



for filename in dist/**/*.js; do
    if [[ $filename =~ "main" ]]; then
        sed -i -e 's/__DOMAIN__/'$DOMAIN'/g' $filename


pm2-runtime start pm2.json --web

Enter fullscreen mode Exit fullscreen mode

The image is used in a Kubernetes deployment:

      - image: <image-repo>
        args: [""]  
Enter fullscreen mode Exit fullscreen mode

envsubst would also be a possibility. You would then use ENV variables in the environmentfiles and use envsubst in the entrypoint script. In the kubernetes deployment you would then add env vars instead of args.

Need more details?

Please let us know if you are interested in more details!

Top comments (0)