How do you handle secrets in Compose?
IntermediateScenarioNetworking and Compose
Answer
Situation read → Env vars leak in docker inspect and logs.
What I'd do →
services:
api:
secrets: [db_password]
environment: { DB_PASSWORD_FILE: /run/secrets/db_password }
secrets:
db_password: { file: ./secrets/db_password.txt }
App reads the file at start. Keep the secrets directory out of git.
Why → Mounted as a read-only tmpfs file at /run/secrets.
Interview tip → In production use a secret manager (Vault, AWS Secrets Manager).
More on Networking and Compose
Containers on the default bridge cannot resolve each other by name. Why, and what do you do?BeginnerHow do you expose a container only to the local host, not the internet?BeginnerDesign a Compose file for web + api + postgres + redis with correct startup ordering.IntermediateFrontend must reach the API but not the database. Segment the network.IntermediateA container needs to call a service running on the Docker host.BeginnerWhen would you use `--network host`?Intermediate