Accessing docker containers servers on LAN

Hello! I am new to Docker, and am trying to connect to docker on other devices on LAN. I’ve run ipconfig and my ip address is say 192.168.1.5.

If I have a basic docker-compose.yml like:

services:
  nginx:
    image: nginx:latest
    ports:
      - "0.0.0.0:80:80"
    volumes:
      - ./nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf

and run docker-compose up. I am unable to connect to 192.168.1.5 on other devices on LAN. I have also tried using 0.0.0.0:8000:80 as I thought perhaps port 80 might be restricted but it still does not work.

If I run services outside of docker-compose, I am able to access them. Such as if I were to run a simple vite application and run it outside of a container via npm run dev, I can modify the config to access the site on any device on LAN.

I would appreciate your help! Thanks you.

I see you used “windows” among the tags, so I assume it is Docker Desktop for Windows, right?

And when you run npm, that runs on Windows in powershell or in a WSL2 distribution?

Yes, Docker Desktop for Windows. When I run npm run dev, I was referring to using git bash, but powershell would work the same.

Couldn’t be that you enabled npm once in the Windows firewall? You can allow applications and ports. I cannot access any of the ports on my Windows from my Mac and I could not configure the firewall either for now. I tried Python by the way and add python3.exe, but it didn’t work. I also tried allowing the port in general, but it didn’t work either. Hopefully you can do it better.

I don’t remember touching the firewall for node (thought it could’ve been the firewall popup certain applications have when you first run it). I think firewall was the main issue here, I added a proxy to point 0.0.0.0:8008 to localhost:80 and enabled inbound tcp to port 8008 and I can connect. Not sure if this is the best way to do it :thinking:.

A published port should be accessible from other hosts in the subnet.
When I tested it a couple of days ago, I couldn’t reach containers using the published host port from remote hosts.

After changing the settings for “Resources” → “Network” → “Default networking mode” to “Dual IPv4/IPv6” , followed by a restart of Docker Desktop, it was working again. The odd part: it continued to work after changing the value back to “ipv4 only”.

Please give it a try, if this solves the issue for you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.