How to Fix the Invalid Interpolation Format Error in Docker Compose

We run into a strange error when we added a new environment variable to our Docker Compose file:

ERROR: Invalid interpolation format for “environment” option in service “api”: “MY_KEY=Abc$5”

Our docker-compose.yaml file looks like this:

The problem is the $ in the value of the environment variable MY_KEY. Docker allows a lot of flexibility in its configuration files. One way to do that is to use variables. Unfortunately, in our case the $ is just a $ and not an indicator for a variable. It is basically the same problem we had a few years ago with DbUp.

We can escape the $ sign by using two $$ to prevent the variable substitution:

With this change we can run docker-compose without any errors. Inside the container, our variable has the right number of $:

The env variable has only one $ sign.

2 thoughts on “How to Fix the Invalid Interpolation Format Error in Docker Compose”

  1. I just faced a similar issue with a docker environment variable not within the .env file but with the docker-compose.tml there was also a definiiton of an env variable inside of the file and the issue of the single “$” was within that file not in the .env i repeat. for example

    JWT_PUBLIC_KEY: “$${JWT_PUBLIC_KEY:—-}”

    Just so if someone else haves an issuw with this you are aware to also look on this file.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.