Docker, Windows and DNS

Problem: In a microservice environment, when communicating between services, how does one service identify the ip address of another service in a docker-compose environment running on Windows?

Assumptions: 

  • linux containers, 
  • bridge docker network settings, 
  • Docker Desktop version 4.35+, 
  • Windows 10+, 
  • container_name attribute has been set, 
  • ping 127.0.0.11 is successful,
  • only communication between containers within the docker-compose environment is of interest.  that is, both containers will be started by docker compose
  • ymmv

Details

From a cmd prompt, trying ping 127.0.0.11.  What is this?  Docker desktop starts with its own dns service.  This will also respond even when no containers are running.  in my experiments, this will also respond when Docker Desktop is not running. 

this is different than if you do a nslookup aaaa, which will use 127.0.0.1.  this will become important in a following article, but can be ignored for the moment.

If you were to start two services - say with the following configuration:

services:
  container1:
    container_name: container1
    image: ...
  
  container2:
    container_name: container2
    image: ...
If you were to jump in - docker exec -it <container> sh - you will be able to enter commands (you can get <container> by doing a docker ps).  Our containers do not have a lot of network tools, but we use curl quite extensively.  From with container1, running the command curl -v http://container2 should resolve.  The curl command will use the internal docker dns to lookup the container name.  

While this might seem pretty straightforward, what happens when we change the container_name?  See my next post for the answer.

references:

Comments

Popular Posts