2

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:

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

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

1.1.1.1 1.1.1.1 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?

1 Answer 1

4

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

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

and here is what I get in the container

cat /etc/hosts ... 1.1.1.1 a1.test.com 1.1.1.1 test.com 

(edit: indentation)

2
  • It was my mistake, I had typo in .env file Commented Oct 23, 2017 at 6:49
  • I'm getting this eror: ERROR: for cron Cannot create container for service cron: bad format for add-host: ":1.1.1.1" with: "${HOSTNAME}:1.1.1.1" Commented Sep 21, 2023 at 15:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.