简体   繁体   中英

No response from server running in Docker container within LAN

I'm not sure if this is a networking issue, or a Docker issue, but I'm having a difficult time getting a response from a server on a separate machine in my LAN that is running a nodejs server on port 3000 in a Docker container. I'm using a Mac computer as a client, and a Linux computer as a server. These are the steps I've taken :

Testing connection to separate computer on LAN using <name of computer>.local:<port>

  • Run server on Linux machine (just using nodejs without a container)
  • On Mac (client) computer run curl <name of linux computer>.local:3000
  • Works as expected

Testing connection to server on localhost while running inside of a Docker container

  • Run server on Linux machine inside of a container using the command docker run -p 127.0.0.1:3000:3000 <name of image>
  • On Linux machine run curl localhost:3000
  • Works as expected

Testing connection to separate computer while running server in Docker container

  • Run server on Linux machine inside of a container using the command docker run -p 127.0.0.1:3000:3000 <name of image>
  • On mac machine run curl <name of linux computer>.local:3000
  • No response from server

The container will not be accessable external to the Linux host when listening on 127.0.0.1 / localhost .

To bind to all available interfaces use:

docker run -p 3000:3000 <image>

Or specify the address of a publicly available interface from ip address show

docker run -p <public_ip>:3000:3000 <image>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM