In most cases, they describe some complex solutions (e.g. And striving to help you to get the maximum outcome from this technology usage, we are regular providing the related guides and tips at our blog. Useful for service discovery tools run from within a container where you want to tell others the host IP so others can find you.Docker containers integration within Jelastic Cloud has become one of the most important and demanded services, offered by a Platform. If the container knows the ip address of its host, you can broadcast this out to other services via the container’s application. I’m using boot2docker, and the boot2docker ip address is 192.168.59.103 and I can accomplish the same tasks as the gateway approach: # Docker processes, via ip:Īlthough there’s no way to introspect the host’s ip address (AFAIK) you can pass this in via an environment variable: docker run -i -t -e DOCKER_HOST=192.168.59.103 ubuntu env
You also have the same access via the host’s ip address. The gateway approach is great because you can figure out a way to access a host from entirely within a container. You can use this for some hakky service-discovery. If you have docker installed in your container you can also query the docker host: # In a container with docker installed list other containers running on the host for other containers:ĬONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESĠ9d035054988 ubuntu:14.04 /bin/bash About a minute ago Up About a minute 0.0.0.0:49153->8080/tcp angry_bardeenĠ0b019ce188c mhamrah/mesos-sample:latest /opt/delivery/bin/de 8 minutes ago Up 8 minutes 0.0.0.0:8080->8080/tcp suspicious_colden If you had a service running on some other port–say Postgres on 5432–not running in a Docker container–you can access it via 172.17.42.1:5432. We just needed to know the port the other service was listening on. Nothing exciting, but you get the picture: it doesn’t matter that the service is inside another container, we’re accessing it via the host, and we didn’t need to use links. We can then curl our other docker container, and we should get that docker container’s hostname: curl 172.17.42.1:8080
We can use the following command to pull out the gateway from netstat: netstat -nr | grep '^0\.0\.0\.0' | awk '' Next we’ll run /bin/bash in another container to do some discovery: docker run -i -t ubuntu /bin/bash This is the docker0 bridge on the host.Īs an example, we’ll run a simple docker container which returns the hostname of the container on port 8080: docker run -d -p 8080:8080 mhamrah/mesos-sample
Essentially you’re using netstat to parse the gateway the docker container uses to access the outside world. You can access the Docker host by its ip address from within a container.You can access the Docker host by the container’s gateway.Accessing the Docker Host Server Within a Container Jun 29 2014ĭocker links are a great way to link two containers together but sometimes you want to know more about the host and network from within a container.