You can pass environment variables to Docker containers in a few different ways, able to pass the environment in Dockerfile, while running the docker container, and docker-compose file.

Set environment variables when you run the docker run command:

docker run -e YOUR_VAR=thelinuxfaq

$ docker run -e YOUR_VAR=thelinuxfaq  nginx-thelinuxfaq bash 

Set environment variables in the Dockerfile:

ENV MY_VAR thelinuxfaq

Set environment variables in a .env file and use --env-file to load the variables into the container at runtime:

$ cat .env

docker run --env-file .env

$  docker run --env-file .env  nginx-thelinuxfaq bash

Set environment variables in the Compose file (for Docker Compose):
      MY_VAR: thelinuxfaq