I have a docker compose file with .env file, for example the .env file has this HOSTNAME=a1.test.com, and a docker-compose file has this:

  - "${HOSTNAME}:"
  - "test.com:"

When I run the container the /etc/hosts file content is:     test.com

So the docker compose not putting the variable data during the run process.

I tried this hostname: "${HOSTNAME}" and it is working fine the host name of the container is correct a1.test.com.

Any idea how can achieve what I want?


I've tried your case, and it works fine on my side:

version: '2'
      image: ubuntu:16.04
      command: sleep 9999
      - "${HOSTNAME}:"
      - "test.com:"

and here is what I get in the container

cat /etc/hosts
... a1.test.com test.com
  • It was my mistake, I had typo in .env file Oct 23 '17 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.