You can pass environment variables to Docker containers in several ways:
1. Using the -e flag: Use docker run -e VAR=value to pass variables directly.
2. Using a .env file: Create a .env file with key-value pairs and use docker run –env-file .env to load them.
3. In the Dockerfile: Use the ENV directive to set default environment variables during build.
4. Using Docker Compose: Define environment variables in the docker-compose.yml file under the environment section or use an .env file with env_file.
These methods ensure configuration flexibility.