Docker compose on Windows and ip addresses

Continuing from the previous article.

Problem: how does docker on Windows differ from docker on Linux related to ip addresses assigned to containers?

We have a bit of background to cover before hitting ports. If we were to modify the docker compose to look like

services:
  container1:
    container_name: container1
    image: ...  
    ports:
      - "100:100"
      
  container2:
    container_name: containerA 
    image: ...
    ports:
      - "200:200"
    
  container2A:
    container_name: containerA
    image: ...
    ports:
      - "200:200"
    

And we run docker compose up container1 container2, what are the ip addresses for the containers in windows? While the external ip address is your computers ip address, on Windows, there is a network setup using 172.18.0.0/16 subnet and each container gets a dynamically assigned ip.  You can see this in the Networks section of a docker inspect <container>.  Output looks like:

"MacAddress": "02:42:ac:12:00:04",
"DriverOpts": null,
"NetworkID": "6d8d4974f63c45e9d296672d57bbd36de95839510237cb62fadbe8c643baf6e8",
"EndpointID": "6140a96f5c107a246e4b8ea4eb62b5ca714d2745dff5d8765fcc666e2a248faa",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.4",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"DNSNames": [
  "container1",
  "3cba943b0aa6"
]

Notice here that the two dns entries.

You can probably guess by the title that there is a difference when running outside docker compose in Linux.  We will hit this in subsequent posts.

References

Comments

Popular Posts