将vhosts分配给Docker端口 [英] Assigning vhosts to Docker ports

查看:112
本文介绍了将vhosts分配给Docker端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一个通配符DNS,以便所有到自定义域(* .foo)的Web请求映射到Docker主机的IP地址。如果我有多个容器运行Apache(或Nginx)实例,每个容器将Apache端口(80)映射到一些外部入站端口。



我想做的是通过我的自定义DNS服务器向已经映射到正确的IP地址(Docker主机)的container-1.foo发出请求,但是将缺省端口80请求代理到正确的Docker外部端口,以便正确的Apache实例从指定的容器可以根据自定义域进行响应。同样,container-2.foo将代理第二个容器的apache,等等。



是否有预先构建的解决方案,是我最好的选择运行Docker主机上的Nginx代理,还是应该编写一个可以管理Docker容器(通过网络启动/停止/重新启动)的node.js代理?我有什么选择可以使Docker容器更像一个自然事件,而不是一些无关的端口和容器玩杂耍?

解决方案

p>这个答案可能有点迟了,但请看 Jason Wilder的nginx-proxy Docker图像。当运行此映像的Docker容器时,您将获得一个nginx服务器,作为其他容器的反向代理,无需维护。



只需运行其他容器使用 VIRTUAL_HOST 环境变量,nginx-proxy将发现他们的ip:port,并为您更新nginx配置。



让我们说你的DNS设置使得<。c $ c> *。test.local 映射到Docker主机的IP地址,然后只需启动以下容器即可快速演示运行:

 #启动反向代理
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock jwilder / nginx-proxy

#为http://tutum.test.local启动第一个容器
docker run -d -eVIRTUAL_HOST = tutum.test.localtutum / hello-world

#为http://deis.test.local启动第二个容器
docker run -d -eVIRTUAL_HOST = deis.test.localdeis / helloworld


I have a wildcard DNS set up so that all web requests to a custom domain (*.foo) map to the IP address of the Docker host. If I have multiple containers running Apache (or Nginx) instances, each container maps the Apache port (80) to some external inbound port.

What I would like to do is make a request to container-1.foo, which is already mapped to the correct IP address (of the Docker host) via my custom DNS server, but proxy the default port 80 request to the correct Docker external port such that the correct Apache instance from the specified container is able to respond based on the custom domain. Likewise, container-2.foo would proxy to a second container's apache, and so on.

Is there a pre-built solution for this, is my best bet to run an Nginx proxy on the Docker host, or should I write up a node.js proxy with the potential to manage Docker containers (start/stop/reuild via the web), or...? What options do I have that would make using the Docker containers more like a natural event and not something with extraneous ports and container juggling?

解决方案

This answer might be a bit late, but take a look at Jason Wilder's nginx-proxy Docker image. When running a Docker container of this image, you get a nginx server set up as a reverse proxy for your other containers with no config to maintain.

Just run your other containers with the VIRTUAL_HOST environment variable and nginx-proxy will discover their ip:port and update the nginx config for you.

Let say your DNS is set up so that *.test.local maps to the IP address of your Docker host, then just start the following containers to get a quick demo running:

# start the reverse proxy
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock jwilder/nginx-proxy

# start a first container for http://tutum.test.local
docker run -d -e "VIRTUAL_HOST=tutum.test.local" tutum/hello-world

# start a second container for http://deis.test.local
docker run -d -e "VIRTUAL_HOST=deis.test.local" deis/helloworld

这篇关于将vhosts分配给Docker端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆