Easiest way to connect Docker container to local host

∥☆過路亽.° 提交于 2019-12-14 03:50:56

问题


I am wondering if is it possible to connect to an app on local host from Docker container.

I run two Docker container which are connected to each other via link option. But how can I connect one of the containers to the local host?


回答1:


Yes, use docker run --network=container:<container-id>

--network='container:': reuse another container's network stack

This let you run a container sharing the same network interface (then localhost) from another container.


Alternatively, you can use the host mode to give your containers the same network ips that the host has (including localhost). docker run --network=host:

--network= 'host': use the Docker host network stack

Docs: https://docs.docker.com/engine/reference/run/#name-name




回答2:


I think it is possible. Try communicate with the host's<ip:port>

ip: useip addror something similar to get the one of eth0,not the one of docker0

port:the one you assigned to the app

To make the process easier,perhaps turn selinux and firewall down when you try.



来源:https://stackoverflow.com/questions/45045741/easiest-way-to-connect-docker-container-to-local-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!