Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access tomcat running in docker container from browser?

Tags:

I am running tomcat in my docker container from the Official Repo.

docker pull tomcat 

And as per guidelines stated in the homepage I've run the instance and the Tomcat server is started

docker run -it --rm -p 8888:8080 tomcat:8.0 

And Tomcat server is available on the port 8888. I am able to get the response in the boot2docker when I execute the following command

curl localhost:8888 

But I would like to access the page from my web browser installed in my PC (which is out of the Virtual Box, the one that is installed in my Windows). Can I? If so how?

like image 913
JavaTechnical Avatar asked Dec 14 '14 16:12

JavaTechnical


People also ask

How can I tell if Tomcat is running in Docker container?

Show activity on this post. option -p has argument hostPort:containerPort so in your case port 8080 (inside your docker image) is mapped to port 8888 on the host (your windows box). This means you should be able to find the tomcat on your Windows box by appending :8888 to your URL, just like you did with curl.


2 Answers

You may be missing a port forwarding rule in the VirtualBox settings.

boot2docker vm > settings > Network > NAT adapter > Port forwarding 

Note the last entry:

enter image description here

This way you have configured the whole chain: hostPort:virtualBoxPort then virtualBoxPort:containerPort, as shown in the following diagram: enter image description here

like image 166
tduchateau Avatar answered Oct 22 '22 07:10

tduchateau


Seems there's a better answer available since Docker-Tools was introduced a few months ago. If you're not using Docker Tools, take a look at https://docs.docker.com/machine

If you are using Docker Tools,

  1. find the docker machine name with $ docker-machine ls
  2. find the docker IP address with $ docker-machine ip <machine-name>
  3. use the ip address to connect, e.g. $ curl 192.168.99.100
like image 28
Kay V Avatar answered Oct 22 '22 09:10

Kay V