Docker Community Forums

Share and learn in the Docker community.

Access container from dev machine (by ip/dns name)


(Whitecolor) #1

Questions like seem to be asked but I really don’t get it at all.

I have a window 10 dev machine host with docker for windows installed. Besides others networks it has DockerNAT netwrok with IP

I run some containers with docker-compose:

version: '2’
build: .
container_name: web

It created some network bla_default, container has IP, of cource I can not connect to from host - it doesn’t have any netwrok interface for this.

What should I do to be able to access this container from dev machine? (by IP) and if possible by some DNS name? What should I add to my docker-compose.yml, how to configure networks?

Connecting to containers IP address
(Michael Friis) #2

Containers that expose ports are available on localhost:

(Whitecolor) #3

Thanks, I know, but I wan’t to understand is it possible to get access to the container directly to its full ip source, and better to access it using

currently from my dev machine (docker for windows beta) I can not connect to 172.x.x.x container addresses because on this machine I have only NAT interface related to docker. Any advice on this?

(David Maze) #4

No(*), it’s not. Publish ports using docker run -p and access them through localhost, as @friism recommended.

(*) I know for sure that this is impossible on “native” Docker for Mac. I’m guessing “native” Docker for Windows is the same. On a Docker Toolbox installation, if you were really familiar with both the host and Linux IP routing setups, you could probably make it work. But it’s a lot of effort to work around functionality that Docker provides out of the box.

(Whitecolor) #5

Well for now I’ve been able at least to acess 172.x.x.x ips from dev machine by adding needed route:

route /P add MASK

Now want to figure aout is it possible to connect to them using some DNS names (maybe to get immutable connectivity way.

(Whitecolor) #6

Using this - we can quite easiely enable advance DNS discovery and access containers by custom DSN name from dev machine.

SO, YES WE CAN! Oh this not actual.

(Dvdarias) #7

To specifically solve this problem I created a simple “etc/hosts” domain injection tool that resolves names of local Docker containers on the host. Just run:

docker run -d \
    -v /var/run/docker.sock:/tmp/docker.sock \
    -v /etc/hosts:/tmp/hosts \
    --name docker-hoster \

You will be able to access a container using the container name, hostname, container id and vía the network aliases they have declared for each network.

Containers are automatically registered when they start and removed when they are paused, dead or stopped.

(Eaverdeja) #8

Fit as a glove for me! Thanks @dvdarias :slight_smile: