简体   繁体   English

在局域网内的Docker容器中运行的服务器无响应

[英]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. 我不确定这是网络问题还是Docker问题,但是我很难从局域网中另一台计算机上的服务器获得响应,该服务器在Docker的3000端口上运行Node.js服务器容器。 I'm using a Mac computer as a client, and a Linux computer as a server. 我使用Mac计算机作为客户端,使用Linux计算机作为服务器。 These are the steps I've taken : 这些是我已采取的步骤:

Testing connection to separate computer on LAN using <name of computer>.local:<port> 使用<name of computer>.local:<port>在LAN上测试与另一台计算机的连接

  • Run server on Linux machine (just using nodejs without a container) 在Linux机器上运行服务器(仅使用不带容器的nod​​ejs)
  • On Mac (client) computer run curl <name of linux computer>.local:3000 在Mac(客户端)计算机上,运行curl <name of linux computer>.local:3000
  • Works as expected 按预期工作

Testing connection to server on localhost while running inside of a Docker container 在Docker容器中运行时测试与本地主机上服务器的连接

  • Run server on Linux machine inside of a container using the command docker run -p 127.0.0.1:3000:3000 <name of image> 使用命令docker run -p 127.0.0.1:3000:3000 <name of image>在容器内部的Linux计算机上运行服务器
  • On Linux machine run curl localhost:3000 在Linux机器上,运行curl localhost:3000
  • Works as expected 按预期工作

Testing connection to separate computer while running server in Docker container 在Docker容器中运行服务器时测试与单独计算机的连接

  • Run server on Linux machine inside of a container using the command docker run -p 127.0.0.1:3000:3000 <name of image> 使用命令docker run -p 127.0.0.1:3000:3000 <name of image>在容器内部的Linux计算机上运行服务器
  • On mac machine run curl <name of linux computer>.local:3000 在mac机上运行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 . 127.0.0.1 / localhost上侦听时,将无法在Linux主机外部访问该容器。

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 或从ip address show指定公共可用接口的ip address show

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从另一个容器连接到在 docker 容器中运行的 mysql 服务器 - connect to mysql server running in docker container from another container 是否可以使用Docker Compose从正在运行的Docker容器中启动新的Docker容器? - Is it possible to launch a new Docker container from within a running Docker container using Docker Compose? 从Docker容器到LAN IP的HTTPS请求失败,但是curl有效 - HTTPS request from Docker container to LAN IP fails, but curl works 无法从本地主机ping容器中正在运行的服务器 - Can't ping running server within container from localhost 从另一个docker容器内部访问在docker容器中运行的服务 - Access service running in docker container from inside another docker container 如何从 AWS SAM 本地 Docker 容器访问另一个 Docker 容器(运行节点快速服务器)? - How do I access another Docker container (running a node express server) from a AWS SAM Local Docker container? Docker:来自服务器的空响应 - Docker: Empty response from server 来自Docker容器的Gmail OAuth - Gmail OAuth from within docker container 从主机在 docker 容器上运行命令 - Running commands on docker container from the host 在 docker 容器中暴露在 localhost:3000 上运行的 yarn dev 应用程序 - Expose yarn dev app running on localhost:3000 within docker container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM