Its baffling how one get host ip address on windows (boot2docker) by just issuing this command: docker-machine ip
But same doesn't work on ubuntu using same command. It always says : "docker-machine: command not found"
Any idea on why its not working? or is there different command to find the host ip while running ubuntu as the host machine os and docker host?
You can easily get the IP address of any container if you have the name or ID of the container. You can get the container names using the "Docker ps -a" command. This will list all the existing containers.
Accessing the Host With the Default Bridge Mode You just need to reference it by its Docker network IP, instead of localhost or 127.0. 0.1 . Most Docker Engine installations will represent the host as 172.17.0.1 on the default docker0 bridge network.
Listen to Connections in the Docker Network The bridge connection docker0 – with IP address 172.17. 0.1 – is created by Docker at installation time. Because the host and all containers are connected to that network, our application only needs to listen to it.
You can use docker inspect <container id> . In order to extract the ip, you can do something like docker inspect $CID | grep IPAddress | cut -d '"' -f 4 , it works fine :) Just a note.
Instead of using docker-machine commands you could use regular docker commands.
For example if you run the following container
docker run --name some-postgres -p 5432:5432 -d postgres
You can access the container through localhost in port 5432 or you can use docker inspect to find the containers IP
docker inspect --format '{{ .NetworkSettings.IPAddress }}' some-postgres
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With