HOME BLOG

How to set environment variables on Docker containers via docker-compose file

Posted on: August 18th, 2022 by Olu No Comments

Hi folks,

In this post I briefly go over how to set environment variables in your docker container which is managed by a docker-compose.yaml file.

You can use the env_file flag. Suppose you set environment variables in a file .env, you can read environment variables into a container, service_name as follows:

services:
    service_name:
        container_name: service_name
        ...
        env_file:
          - .env

That’s all for now. Till next time, happy software development.

Leave a Reply