简体   繁体   中英

How to Access AWS EC2 docker tomcat instance running inside jenkins docker instance from my local browser

I have a jenkins instance running inside a docker container that's listening on port 8181.

Example URL of the jenkins instance: http://ec2-34-155-164-97.us-west-2.compute.amazonaws.com/

I have a tomcat docker instance that's listening on port 8383 running inside the jenkins docker container.

I can access jenkins instance from my local browser. Is there any possible way that I can access my docker tomcat instance from my local browser?

Here is my docker run command:

docker run -d -v /var/run/docker.sock:/var/run/docker.sock \ -v $(which docker):/usr/bin/docker -p 8181:8080 jenkins-dsl 

Please provide your suggestions.

It sounds like your docker run command simply needs to expose the port that your nested tomcat server is running on.

To do this, you need to pass in -p argument into your command. The -p argument is for binding a host port to the docker container's port:

-p <host_port>:<container_port>

You can pass in as many -p arguments as you want to bind multiple ports.

So if the docker tomcat server is running on port 8383 within the Jenkins docker container, then you can do something like this:

-p 8383:8080

Full command example:

docker run -d -it -p 8383:8080 --name tomcatServer docker-tomcat

I would assume that this would allow you to access tomcat server using the example URL provided like so:

http://ec2-34-155-164-97.us-west-2.compute.amazonaws.com:8383

However, you'd have to ensure your AWS Security Group will allow traffic to port 8383.

EDIT: Updated answer to reflect the resolution we discussed in the comments. Edited

I could able to launch tomcat by specifying the port in the URL and opening the port in EC2 instance.

http://ec2-34-155-164-97.us-west-2.compute.amazonaws.com:8383

Latest Docker installation guide for Tomcat clearly says you will get this error when you launch it for the first time

You can then go to http://localhost:8888 or http://host-ip:8888 in a browser (noting that it will return a 404 since there are no webapps loaded by default).

its because you do not have any apps in the default webapps folder of Tomcat. your latest Tomcat docker image has the default apps in the "webapps.dist" folder, you have to copy it to "webapps" folder. Do the Following commands

#  docker exec -it tomcat-container /bin/bash
#  cd webapps.dist
#  cp -R * ../webapps

"tomcat-container" is your container name. now refresh your browser you will get it. if not let me know

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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