Intermediate Reading #docker-compose #dotenv #yaml #config

Reading App Config & .env Files

5 exercises on reading application configuration: docker-compose.yml services, volumes and networks, .env file security, pass-through environment variables, and YAML anchors.

Config file quick reference
  • env_file: .env — load all KEY=VALUE pairs from a file into the container
  • environment: - KEY (no value) — pass through from host shell environment
  • Never commit real secrets in .env — use .env.example with placeholders instead
  • No ports: on a service = only reachable within the Docker network by service name
  • YAML &anchor + <<: *anchor = define once, reuse with merge
0 / 5 completed
1 / 5

Read this docker-compose.yml services section and answer the question:

services:
  app:
    image: node:20-alpine
    working_dir: /app
    volumes:
      - .:/app
      - node_modules:/app/node_modules
    ports:
      - "3000:3000"
    env_file:
      - .env
    command: npm start

volumes:
  node_modules:
What does the env_file: - .env directive do?