You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of Docker Compose version 2.32.4 (released after February 2025, aligning with the current date of April 10, 2025), there isn’t a built-in, straightforward way to globally enable an optional .env.local file across all services without some customization. However, based on your requirement and the constraints you’ve outlined (avoiding per-service env_file edits and the limitations of COMPOSE_ENV_FILES), here’s the easiest practical approach:
Easiest Solution: Use a Shell Wrapper with COMPOSE_ENV_FILES
You can leverage the COMPOSE_ENV_FILES environment variable in combination with a simple shell script or Makefile to make .env.local optional and globally applied. This avoids modifying the docker-compose.yml file for each service and works with your existing setup.
Steps:
Modify Your Makefile (or Create a Shell Script):
Update your existing Makefile to dynamically include .env.local if it exists, and set it in COMPOSE_ENV_FILES. Here’s how you can adapt it:
makefile
include .env -include .env.local export ifneq ($(wildcard .env.local),) export COMPOSE_ENV_FILES=.env,.env.local else export COMPOSE_ENV_FILES=.env endif up: docker compose up
Run Your Command:
Use the Makefile to start Docker Compose:
In Makefile i use this way:
What is the easiest way to GLOBALLY enable OPTIONAL .env.local in Docker Compose?
In issues and official docs i have found the following options, but they are not simple:
I use Docker Compose version 2.32.4
The text was updated successfully, but these errors were encountered: