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):
sudo docker run -d -p 9090:8080 -p 8888:80 --network public --name traefik -v $PWD/traefik.toml:/etc/traefik/traefik.toml -v /var/run/docker.sock:/var/run/docker.sock traefik
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):
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:
stage ('Postgres: despliegue inicial de la base de datos') {
def dbImage = docker.build("catalogador/catalogador-tfg-db:${BRANCH_NAME}","--label jenkins ./database")
dbHostname = "${BRANCH_NAME}-${BUILD_NUMBER}-db"
db = dbImage.run("-p 5432:5432 --network public --name ${dbHostname}")
timeout(time: 3, unit: 'MINUTES') {
sh "until [ \$(docker logs ${dbHostname} --tail 50 2>&1 | grep 'init process complete' | wc -l) -gt 0 ]; do sleep 10; done"
}
}
stage ('Tomcat: despliegue de la aplicación') {
def webImage = docker.build("asd/asd-tfg-app:${BRANCH_NAME}","--label jenkins ./appserver")
def webJavaOpts = "-Dspring.datasource.url=jdbc:postgresql://${dbHostname}:5432/${dbName} " +
"-Dspring.datasource.username=${dbUser} " +
"-Dspring.datasource.password=${dbPassword} "
webHostname = "${BRANCH_NAME}-${BUILD_NUMBER}-app"
def proxyOpts = "-l 'traefik.frontend.rule=Host:${testingDomainName};PathPrefixStrip:/${webProxyPrefixPath}' " +
"-l 'traefik.port=9090'"
web = webImage.run("-p 9999:8080 -p 9898:80 --network public --link ${dbHostname} --name ${webHostname} -e JAVA_OPTS='${webJavaOpts}' ${proxyOpts}")
timeout(time: 3, unit: 'MINUTES') {
sh "until [ \$(docker logs ${webHostname} --tail 50 2>&1 | grep 'Server startup' | wc -l) -gt 0 ]; do sleep 10; done"
}
}
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.
I have had a very similar issue, where i have configured the CNAME of the subdomain to point to the same machine where my docker container is running, launched an Nginx reverse proxy which listens to all docker containers and then forward all trafic coming from port 80 to the desired container. Works like a charm in production as well. this way 1 machine can serve multiple docker containers with different sub domains :) let me know if it's not clear i can provide examples and links to solve the problem.
This is the nginx docker image i'm using, which listens to all container on the machine, and forward the http requests to the specific container based on an environment variable a container has been started, setting the subdomain variable as described in the README of the link below. enter link description here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With