How to get Docker host IP on Travis CI? How to get Docker host IP on Travis CI? docker docker

How to get Docker host IP on Travis CI?


I think what you want is actually the container IP, not the docker engine IP. On your desktop you had to query docker-machine for the IP because the VM docker-machine created wasn't forwarding the port.

Since you're exposing a host port, you can actually use localhost for the host value.

There are two other options as well:

  • run the tests in a container and link to the database container, so you can just use postgres as the host value.
  • if you don't want to use a host port, you can use https://github.com/swipely/docker-api (or some other ruby client) to query the docker API for the container IP, and use that for the host value. Look for the inspect or inspect container API call.


For others coming across this, you should be able to get the host IP by running

export HOST_IP_ADDRESS="$(/sbin/ip route|awk '/default/ { print $3 }')"

from within the container. You can then edit your database configuration via a script to insert this in - it'll be in the $HOST_IP_ADDRESS variable.

However like dnephin said, I'm not sure this is what you want. This would probably work if you were running Travis' Postgres service and needed to access it from within a container (depending on which IP address they bind it to).

But, it appears you're running it the opposite way to this, in which case I'm fairly sure localhost should get you there. You might need to try some other debugging steps to make sure the container has started and is ready, etc.

EDIT: If localhost definitely isn't working, have you tried 127.0.0.1?