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 10.0.75.1
I run some containers with docker-compose:
version: '2’
services:
web:
build: .
container_name: web
It created some network bla_default, container has IP 172.18.0.4, of cource I can not connect to 172.18.0.4 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?
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 10.0.75.0 related to docker. Any advice on this?
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.
Using this https://github.com/aacebedo/dnsdock - 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.
MAKE DOCKER GREAT AGAIN!
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:
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.