In this blog, you will learn to access environment variables in your code with docker-compose.yml. This blog assumes that you are using python . To start off, if you are curious about how you can use environment variables in your code from docker-compose file, basically it takes variable assigned to variables under the "environment" section in the docker-compose file. A picture below will demonstrate how it works. 1 - Docker Compose where you initialize the environment variable 2 - The code where you use the environment variable 3 - The output Method 1: Using .env This is probably one of the most common method because it is easy to use. However, if you use this method, you will need to remember to add this file into .gitignore if you are storing private credentials. 1) To start with, create your .env file and insert your environment variables like so: KEY=VALUE 2) Next, add this line of code below the service that would be using the environment variables in your .env file. ...