Docker Community Forums

Share and learn in the Docker community.

External Env File on Dockerfile

Hi everyone. I have a question about Dockerfile and I can’t find the answer on Docker documentation.
It is possible to have something like .env file for a Dockerfile?

The reason I’m looking for this is simple. I made a Laravel App and I want to distribuite it within a single container (Webserver, Database, app files, etc…) but I would like to store some values inside a diferent file instead of having them hardcoded.

I already thought in docker-compose, but my idea is to have only one single image to get easy using this service.

You can set default values for any environment variables referenced in the Compose file, or used to configure Compose, in an environment file named .env:

$ cat .env
TAG=v1.5

cat docker-compose.yml version: '3' services: web: image: "webapp:{TAG}"

1 Like

Thanks for replying me. My goal is to use the auto build function of docker hub. Does it work with docker compose?