本文介绍了在docker环境中设置子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu服务器(14.04 Trusty Tahr)上在Docker Containers中运行不同的服务。我目前的安装程序如下:




  • Jenkins jenkins.slarti

  • Gitlab和leanlabs .io在gitlab.slarti下

  • servlet.slarti下的Java Servlet Webserver(apache tomcat)

  • 正常web.slarti下的Webserver(nginx)



这些域名是virtualhost,我已经设置了一个nginx代理。



Nginx-proxy docker运行:

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

Jenkins码头运行:

  docker run -d --name jenkinsci --expose 8080 -e VIRTUAL_HOST = jenkins.slarti -e VIRTUAL_PORT = 8080 jenkins 

正常的Webserver码头运行:

  sudo docker run --name nginx1 -P -d --expose 80 -e VIRTUAL_HOST = web.slarti nginx 


$ b $ gitlab&运行:

  docker run -d --link kanban_redis:kanban_redis -p 80:80 -e KANBAN_SERVER_HOSTNAME = http:// localhost-e KANBAN_GITLAB_URL =http://mygitlab.com-e KANBAN_REDIS_ADDR =kanban_redis:6379--expose 80 -e VIRTUAL_HOST = gitlab.slarti leanlabs /看板:1.4.0 

Apache Tomcat docker运行:

  docker run -it --rm -p 8888:8090 -e VIRTUAL_HOST = servlet.slarti tomcat:8.0 

我根据本指南进行了设置



目前我无法ping网页。 slarti,servlet.slarti等。如果我在浏览器中输入网址,我也不能达到这些域名。



我可以通过slarti来达到Apache Tomcat:8888但是我想通过servlet.slarti达到它,并且自从我失败了没有DNS设置。



我必须做什么才能访问子站点web.slarti,servlet.slarti等?如何正确设置逆向代理,以便我可以访问域?我如何配置DNS?

解决方案

我不是网络的专家。但是在阅读你的帖子后,您似乎需要一个这样的DNS配置:

  A  - > slarti(或IP)
CNAME jenkins.slarti - > slarti
CNAME gitlab.slarti - > slarti
CNAME servlet.slarti - > slarti
CNAME web.slarti - > slarti

这是我将我的子域重定向到Docker容器所做的。



没有适当的DNS配置,您的子域名无法访问。



使用此DNS配置,每次您请求gitlab .slarti ,你实际上会到达Nginx,然后再将你重定向到正确的Docker容器(如果 VIRTUAL_HOST 环境变量配置为gitlab。 slarti )。


I am running different services in Docker Containers on my Ubuntu server (14.04 Trusty Tahr) at home. My currently Setup at the moment is as following:

  • Jenkins jenkins.slarti
  • Gitlab and leanlabs.io under gitlab.slarti
  • Java Servlet Webserver under servlet.slarti (apache tomcat)
  • "Normal" Webserver under web.slarti (nginx)

These domains are virtualhost's and I have already setup an nginx proxy.

Nginx-proxy docker run:

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

Jenkins docker run:

docker run -d --name jenkinsci --expose 8080 -e VIRTUAL_HOST=jenkins.slarti -e VIRTUAL_PORT=8080 jenkins

Normal Webserver docker run:

sudo docker run --name nginx1 -P -d --expose 80 -e VIRTUAL_HOST=web.slarti nginx

Gitlab & leanlabs.io docker run:

docker run -d  --link kanban_redis:kanban_redis -p 80:80 -e KANBAN_SERVER_HOSTNAME="http://localhost"  -e KANBAN_GITLAB_URL="http://mygitlab.com"  -e  KANBAN_REDIS_ADDR="kanban_redis:6379" --expose 80 -e VIRTUAL_HOST=gitlab.slarti leanlabs/kanban:1.4.0

Apache Tomcat docker run:

docker run -it --rm -p 8888:8090 -e VIRTUAL_HOST=servlet.slarti tomcat:8.0

I did the setup according to this guide http://blog.florianlopes.io/host-multiple-websites-on-single-host-docker

Currently I can't ping web.slarti, servlet.slarti etc. Neither can i reach these domains if i type their url in the browser.

I can reach Apache Tomcat via slarti:8888 but I want to reach it through servlet.slarti and that fails since i don't have a DNS setup.

What do I have to do to reach the subdomains web.slarti, servlet.slarti etc? How do I setup the reverse proxy correctly so I can reach the domains? And how do I have to configure the DNS?

解决方案

I am not expert on networks. But after reading your post, it appears that you do need a DNS config like this:

A -> slarti (or IP)
CNAME jenkins.slarti -> slarti
CNAME gitlab.slarti -> slarti
CNAME servlet.slarti -> slarti
CNAME web.slarti -> slarti

This is what I have done to redirect my subdomains to my Docker containers.

Without proper DNS configuration, your subdomains can't be reached.

With this DNS config, everytime you request gitlab.slarti, you actually reach Nginx, which in turn redirects you to the proper Docker container (if the VIRTUAL_HOST environment variable is configured to gitlab.slarti).

这篇关于在docker环境中设置子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 12:01