简体   繁体   English

无法设置网络以从外部访问Docker容器IP?

[英]Unable to setup networking to access docker container IPs from outside?

Context: 语境:
I have a web server hosting a UI from which users can request for emulator instances for my product. 我有一台托管用户界面的Web服务器,用户可以从中请求产品的仿真器实例。 Each emulator instance is a webapp running on nodejs. 每个仿真器实例都是在nodejs上运行的Web应用程序。 When a user requests an emulator instance from the UI, I spawn a docker container. 当用户从UI请求仿真器实例时,我产生了一个docker容器。 I would like to return to the user an IP address(+port) from which this emulator container can be accessed. 我想向用户返回一个可以从其访问此仿真器容器的IP地址(+端口)。
Note: Presently, docker and the webserver facing the user are running on the same system. 注意:目前,码头工人和面对用户的网络服务器正在同一系统上运行。

Problems: 问题:
1) The default container on the docker0 network is accessible only with it's local IP address on the host. 1)只能使用主机上的本地IP地址访问docker0网络上的默认容器。 eg http://172.17.0.5 . 例如http://172.17.0.5 I can't access the container with http://localhost:32768 (container was started with -P and was assigned the port 32768). 我无法使用http:// localhost:32768访问该容器(该容器以-P启动,并被分配了端口32768)。 I get a message that the site can't be reached. 我收到一条消息,指出无法访问该网站。

2) I can't use the docker host network driver because the emulator uses ports internally which I don't want to expose in the host network 2)我不能使用docker主机网络驱动程序,因为模拟器内部使用了我不想在主机网络中公开的端口

3) I don't want to use the macvlan driver because I will be using up too many IPs. 3)我不想使用macvlan驱动程序,因为我将使用太多IP。

Is it possibly to map various ports on the host to IPs on the docker0 subnet? 是否可以将主机上的各个端口映射到docker0子网中的IP? If yes, how do I go about this? 如果是,我该如何处理? If this is possible I could expose the host IP and the container specific port to the user. 如果可能的话,我可以向用户公开主机IP和特定于容器的端口。

What is best way to give users access to the containers? 授予用户访问容器的最佳方法是什么?

How about a nginx container acting as a proxy? nginx容器充当代理怎么样? Make your containers have same name always. 使您的容器始终具有相同的名称。

Serve new app instance: 服务新的应用实例:

docker run -d --rm --name=static_prefix__unique_id your_image

Have a wildcard domain: 具有通配符域:

unique_id.yourdomain.com

Or simply: 或者简单地:

yourdomain.com/unique_id

You can dynamically proxy the request (I assume you're using port 3000 for the nodejs app): 您可以动态代理请求(我假设您正在为nodejs应用使用端口3000):

proxy_pass http://static_prefix__$extractedNameFromRequestUri:3000

Docker will do the hard job for you and route traffic from outside to the static_prefix__unique_id container. Docker将为您完成艰苦的工作,并将流量从外部路由到static_prefix__unique_id容器。

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

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