How can I create a subdomain to expose an application running into a docker container in Jenkins pipeline

时间:2018-05-06 17:11:37

标签: docker tomcat jenkins devops traefik

everyone:

I have bitnami jenkins released in an ec2 instance of AWS. On the same machine I am launching my pipeline in which I use docker for several processes, one of them launching a database and a tomcat for a.war application. The fact is that I want to be able to access it from a subdomain or another domain (the application I launch in that docker container to be able to observe the changes).

For this I am using traefik and I can see all the containers running within the same EC2 network. I can also redirect it to a certain url. What I don't know is how to create a new subdomain to make this work. Traefic launched it with the following command (so you can see how I map the ports):

main()

In the following image I show traefik with the ip I want to expose to the outside and a path (in this case it is the domain with an extension, but I have also tried the subdomain):

enter image description here

The traefic configuration file is the following in pastebin:link to configuration file in pastebin

From what I have seen, the bitnami application uses tomcat, correct me if not. I have the domain in freenom, since it is a test that I am doing.

It would be worthwhile to create a subdomain, as well as an extension: http:/midominio.ga/test

Thank you very much, any help is welcome.


Edit 1: I know I can expose it out by mapping the container port to a free EC2 port where I run jenkins, but I preferred to create it in a subdomain or ideally in an extension of the original domain dynamically.

Edit 2:

I'll try to explain my case better. I have an EC2 instance running bitnami jenkins. Inside my pipeline I have the following:

main()

What I want to know is how to create a subdomain within this EC2 instance using Bitnami Jenkins. So instead of accessing my application through http: //mydomain:9999, you can access it through the url of the subdomain http: //subdomain.mydomain.com or the normal domain with an extension http:// mydomain.com/extension.

I don't know how to do it because the image of bitnami jenkins has tomcat, apache2, etc. I don't even know which one it is using. I think tomcat, because that's where he's got the jenkins war. Even create each time I run my pipeline a different subdomain could be great.

Thank you again.

1 个答案:

答案 0 :(得分:1)

我遇到了一个非常相似的问题,即我已将子域的CNAME配置为指向运行我的docker容器的同一台机器,启动了Nginx反向代理,该代理监听所有docker容器,然后转发所有即将到来的流量从端口80到所需的容器。在生产中也像魅力一样起作用。这样一台机器可以为具有不同子域的多个docker容器提供服务:)让我知道是否不清楚,我可以提供示例和链接来解决问题。

这是我正在使用的nginx docker映像,它侦听机器上的所有容器,并根据容器已启动的环境变量将http请求转发到特定的容器,如中所述设置子域变量下面链接的自述文件。 enter link description here