connecting from docker container to docker host
All you need is Docker's link capabilities [deprecated]
Just get rid of all the complicated stuff you tried to do and start using named containers and then link them to each other.
Elias's answer is correct, but the link is long and confusing. Here's a simple summary:
First, run the container to link to, and name it:
sudo docker run -d --name db training/postgres
Then run the other container, linking it to the first container:
sudo docker run -d -P --name web --link db:db training/webapp python app.py
The link from the first container to the second container is put into /etc/hosts
. So you can use it like a hostname. For example:
sudo docker run --name web --link db:db training/webapp ping db