1

I use a mac to run docker and hence I am dependent on boot2docker or docker-machine . My application running in the container needs the docker host's ip.

I saw that the variable substitution feature of docker-compose is exactly what I need . When I try something like the below it works fine

extra_hosts:  
 - "somehost:162.242.195.82"

BUT when I try something like:

export DOCKER_HOST="64.88.225.66"



extra_hosts:  
      - "host:${DOCKER_HOST}"

I get :

$ docker-compose build --no-cache
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "/code/compose/cli/main.py", line 54, in main
  File "/code/compose/cli/docopt_command.py", line 23, in sys_dispatch
  File "/code/compose/cli/docopt_command.py", line 26, in dispatch
  File "/code/compose/cli/main.py", line 169, in perform_command
  File "/code/compose/cli/command.py", line 53, in project_from_options
  File "/code/compose/cli/command.py", line 89, in get_project
  File "/code/compose/cli/command.py", line 70, in get_client
  File "/code/compose/cli/docker_client.py", line 28, in docker_client
  File "/code/.tox/py27/lib/python2.7/site-packages/docker/client.py", line 58, in __init__
  File "/code/.tox/py27/lib/python2.7/site-packages/docker/utils/utils.py", line 362, in parse_host
docker.errors.DockerException: Bind address needs a port: 64.88.225.66
docker-compose returned -1

I'm not sure why it wants a port. It wasn't happy when I gave it a port number too.

So, how can I get my docker host ip to my container? It would be nice if i can pass commands like boot2docker ip or docker-machine ip default in the extra_hosts section or maybe if docker-compose could execute a script to get this value it would be great !

1 Answer 1

2

The problem is that DOCKER_HOST is a variable used by docker-compose itself (https://docs.docker.com/compose/reference/overview/#docker-host) and the format is wrong (it needs a tcp:// scheme and a port I believe).

You'll have to choose a different variable to include it in extra_hosts:.

Otherwise you could just pass it in as an environment variable (environment: [DOCKER_HOST=]) and parse the ip address out of it in the container.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah that's right , thank you so much ! It would be nice if i could do something like extra_hosts: -"some_host:sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.