Skip to main content

Environment Variables

Updated Mar 11, 2022 ·

Overview

Environment variables allow us to use configurable values in our code without modifying the code itself. This flexibility is beneficial for changing settings without redeploying applications.

Ways to Define Environment Variables

  • Dockerfile

    • Use the ENV directive to set variables.
    • Automatically available in the container.
  • Environment File

    • Store variables in a .env file.
    • Load them when starting a container.
  • Shell Environment Variables

    • Set variables in the terminal session.
    • Pass them to the container at runtime.
  • Compose File

    • Define variables in docker-compose.yml.
    • Simplifies configuration for multi-container applications.

Additional Resources