简体   繁体   English

在特定URL运行Docker容器

[英]Running docker container at specific URL(s)

Just started implementing docker containers, I'm not sure if it is possible or not yet. 刚开始实现docker容器,我不确定是否可能。 Is it possible to publish a docker container based on URL or at specific host header? 是否可以基于URL或特定主机头发布docker容器? For example, two containers running at port 192.168.1.2 and port 80 but the first container has website abc.com and the second container has website xyz.com. 例如,两个容器在端口192.168.1.2和端口80上运行,但第一个容器的网站为abc.com,第二个容器的网站为xyz.com。

Can we use some reverse proxy server eg NGINX (or any other that you suggest) to direct web request to respective docker container? 我们可以使用某些反向代理服务器(例如NGINX(或您建议的任何其他代理))将Web请求定向到相应的Docker容器吗?

不,您不能有“两个在IP 192.168.1.2和端口80上运行的容器”,但是可以在IP 192.168.1.2和端口80上运行反向代理,并路由到在不同IP +端口上运行的容器。

Yes, you could do that, you can run a nginx container (or in the host) and it will redirect the content to the right container using the requested server name. 是的,您可以这样做,可以运行一个nginx容器(或在主机中),它将使用请求的服务器名称将内容重定向到正确的容器。

You can map the nginx 80 port in the nginx container to the host and link the others containers to it and then configurate nginx to do the proxy. 您可以将nginx容器中的nginx 80端口映射到主机,并将其他容器链接到该主机,然后配置nginx进行代理。

Here is a post about how to do it: 这是有关如何执行此操作的帖子:

http://www.yannmoisan.com/docker.html http://www.yannmoisan.com/docker.html

If you want to generate nginx configuration dynamically when you start/stop docker containers, you can consider using jwilder/nginx-proxy project. 如果要在启动/停止Docker容器时动态生成nginx配置,可以考虑使用jwilder / nginx-proxy项目。 This will give you more flexibility when deciding your domains. 这将为您在确定域时提供更大的灵活性。

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

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