environment: Sets environment variables for a service, as a list or a map. Often paired with an env_file. In Docker Compose, environment sets environment variables for a service. You can write them as a list, - APP_ENV=production, or as a map, APP_ENV: production. It is often combined with env_file, which loads variables from a file such as .env. Values in environment take priority, which is handy for overriding one setting per service.
Keep secrets out of the Compose file itself, especially if it is committed to Git. Reference variables from your shell or an env file instead, as in DB_PASSWORD: ${DB_PASSWORD}. Add the .env file to .gitignore and commit a .env.example with placeholder values. That way a new developer knows which settings exist, without anyone sharing real passwords through the repository.
What does an example of environment look like?
services: web: environment: NODE_ENV: production DATABASE_URL: postgres://db:5432/app
Use when working with environment variables, .env files and configuration in a Laravel app - adding a new setting, APP_KEY, database/mail/queue credentials, config caching, secrets in CI/CD or Docker, or debugging "env() returns null in production". Keeps secrets out of Git and config reads cache-safe.
Use this skill when creating, modifying, or debugging Docker Compose configurations, even if the user just says they need to wire services together, add a database to their stack, or set up a local development environment with multiple containers. Covers service definitions, health checks, dependency ordering, volumes, networks, environment variables, and development overrides.
Implement secure secrets management for CI/CD pipelines using Vault, AWS Secrets Manager, or native platform solutions. Use when handling sensitive credentials, rotating secrets, or securing CI/CD environments.