dev-resources.site
for different kinds of informations.
docker-compose will always load .env
Published at
5/30/2024
Categories
docker
env
Author
byte4bike
Author
9 person written this
byte4bike
open
Update 6th-Jun-2024
After deeper dive into the docs and practice. I realize I mixed up .env and file.env. Please refer to -> https://dev.to/tbroyer/comment/2fhdp, that's the right way of understanding this concept.
As shown in the screenshot, I didn't specify .env
under any env_file
directives. But it choose to use the PORT
value defined under .env
instead of public.env
or private.env
.
Versions
- docker: 24.0.0
- docker-compose: 1.29.2
Possible Solution
- Remove '.env'
- Never use variable names that are already defined in
.env
My Take
I think more people should be aware of this default behavior and I am interested to know how others deal with this issue.
Code Snippet
Checkout the code snippet below if the screenshot is not clear.
# docker-compose.yml
version: "3.8"
services:
private:
container_name: private_server
build: ./backend
command: uvicorn main:app --host=0.0.0.0 --port=7000
ports:
# - 127.0.0.1:${PUBLIC_PORT}:7000
- 127.0.0.1:${PORT:-7001}:7000
environment:
- WORKSPACE=secret
env_file:
- private.env
public:
container_name: public_server
build: ./backend
command: uvicorn main:app --host=0.0.0.0 --port=7000
ports:
# - 127.0.0.1:${PRIVATE_PORT}:7000
- 127.0.0.1:${PORT:-7000}:7000
environment:
- WORKSPACE=client
env_file:
- public.env
Environment File
# .env
PORT=9879
# public.env
PORT=7000
# private.env
PORT=7001
docker-compose config
services:
private:
build:
context: /home/server/projects/server/backend
command: uvicorn main:app --host=0.0.0.0 --port=7000
container_name: private_server
environment:
PORT: '7001'
WORKSPACE: secret
ports:
- 127.0.0.1:9879:7000/tcp
public:
build:
context: /home/server/projects/server/backend
command: uvicorn main:app --host=0.0.0.0 --port=7000
container_name: public_server
environment:
PORT: '7000'
WORKSPACE: client
ports:
- 127.0.0.1:9879:7000/tcp
version: '3.8'
env Article's
30 articles in total
How to Use Environment Variables in a React.js App with Vite
read article
next-runtime-env usage in Documenso source code
read article
How to Build an Elm Land Project for Production
read article
การใช้ GitLab สำหรับแชร์ Configuration ให้คนในทีม โดยไม่ใช้แชท
read article
How to create a fullstack application using Django and Python Part 5
read article
Exploring DotenvX
read article
Setting up a React environment
read article
Using environment variables in React and Vite
read article
Exploring Node.js 20.6: Built-in Support for .env Files
read article
docker-compose will always load .env
currently reading
How to fix 'process' is not defined (React+Vite)
read article
Virtual Environments in Python Applications
read article
Decoding the Matrix: The Evolution of Environment Variables in Software
read article
Use Doppler instead of traditional .env files 🍕
read article
Além do básico: Uso de Variáveis de Ambiente em Aplicações Node e Nest
read article
Running scripts in Production
read article
Better DX for .env
read article
Navigating Environment Variables in Flutter Projects: Strategies for Effective Integration
read article
TIL - Today I Learn 12-11 18-11
read article
Generate a Random JWT Secret Key
read article
Next JS might be exposing your backend environment variables
read article
Environment variables and configuration anti patterns in Node.js applications
read article
Node(20.6.0) now supports built-in .env files
read article
How to keep your tokens secret?
read article
Criando um comando Artisan personalizado para definir valores de variáveis no .env no Laravel
read article
How to Effectively Remove .env File from Git Repo/History
read article
Vite environment variable's type casting/transforming
read article
Did you know docker-compose only takes environment variables from`.env` only?
read article
[HUGO]: How to use variables from .env
read article
Python – AWS Secrets Manager: Remote env vars
read article
Featured ones: