[英]Connect from Docker to Local Host
I have a docker container basically running Athena Tool Kit for PDF generation. 我有一个基本上运行Athena Tool Kit进行PDF生成的docker容器。 The service in docker in turn calls a NodeJs Application at this URL: - http://localhost:3005 .
泊坞窗中的服务又通过以下URL调用NodeJs应用程序: -http:// localhost:3005 。
However I see a message on Docker Console:- 但是我在Docker控制台上看到一条消息:-
[GIN] 2019/08/23 - 22:24:46 | 500 | 1.850464ms | 192.168.99.1 | GET /convert
Error #01: Get http://localhost:3005/presentations/d0161fed-0ade-40a5-8dff-26696e553e96?id=d0161fed-0ade-40a5-8dff-26696e553e96&type=box-upload¶ms=: dial tcp 127.0.0.1:3005: connect: connection refused
captured errors:
Error #01: Get http://localhost:3005/presentations/d0161fed-0ade-40a5-8dff-26696e553e96?id=d0161fed-0ade-40a5-8dff-26696e553e96&type=box-upload¶ms=: dial tcp 127.0.0.1:3005: connect: connection refused.
The Docker Service runs locally at http://192.168.99.100:8080 . Docker服务在http://192.168.99.100:8080本地运行。 From this address it is trying to call 127.0.0.1:3005.
它试图从该地址呼叫127.0.0.1:3005。 When it does I get the error above.
当它出现时,我得到上面的错误。
I am guessing this must be allowing access to local host from a different IP. 我猜想这一定是允许从其他IP访问本地主机。
Please let me know what needs to be done. 请让我知道需要做什么。
as I can see, you are running to applications, the first one is patelsan/presentations-pdf-toolkit
with a docker container and the second one is a nodejs application within your host. 如我所见,您正在运行应用程序,第一个是
patelsan/presentations-pdf-toolkit
容器的patelsan/presentations-pdf-toolkit
,第二个是主机中的nodejs应用程序。
your problem here that the two application running in two different networks, the host network for nodejs app and the docker bridge default network as a default network for your container.
这里的问题是,这两个应用程序运行在两个不同的网络中,nodejs应用程序的主机网络和docker bridge默认网络作为容器的默认网络。
otherwise as mentioned in Docker doc Docker network host : 否则,如Docker doc Docker网络主机中所述 :
The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.
主机网络驱动程序仅在Linux主机上工作,而Mac的Docker桌面,Windows的Docker桌面或Windows Server的Docker EE不支持该主机网络驱动程序。
I have 3 solutions for both local and prod environments: 我有3种针对本地和产品环境的解决方案:
as a local env solution, you can assign the patelsan/presentations-pdf-toolkit
container to the default host
network in the docker, in this way both applications can communicate with each other: 作为本地环境解决方案,您可以将
patelsan/presentations-pdf-toolkit
容器分配给patelsan/presentations-pdf-toolkit
中的默认host
网络,通过这种方式,两个应用程序可以相互通信:
- run the `patelsan/presentations-pdf-toolkit` container:
- `docker network connect host container_name`
you can use weave net service to create a virtual network. 您可以使用编织网络服务来创建虚拟网络。
NP: NP:
If your host is Windows or Mac I suggest you containerize the nodejs application as well, with that you can create a new network and your 2 containers can communicate with that network. 如果您的主机是Windows或Mac,我建议您也将nodejs应用程序容器化,这样您就可以创建一个新的网络,并且您的2个容器可以与该网络通信。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.