Search code examples
tomcatdockervmwarevmware-workstation

How to access tomcat docker container running in VMWare workstation?


I know this question sound as a repeat question, but I couldn't find other that suit to my requirement. So I just started to use docker for developing tomcat app.

After installing docker in Ubuntu 16 inside VMWare Workstation, and downloading tomcat-docker image, I want to start the tomcat container using START command instead of RUN.

I use START command because I don't want to stuck within STDOUT, and able to continue using Linux command line. So I start the container by using below command

 $ docker start name_of_container

Then I issue inspect command

 $ docker inspect name_of_container

I manage to see that my tomcat instance is using ip: 172.17.0.2. So I did curl like:

 $ curl 172.17.0.2:8080 | head

And I got my HEAD tags printed perfectly, which means that I successfully instantiate my tomcat.

My question is: how can I access my tomcat from my browser in Windows? how can I create a port forwarding in VMWare to enable me to access ip 172.17.0.2??

Thanks


Solution

  • If using docker create to create the container, specify the ports to publish to the host with --publish:

    docker create --publish 8080:8080 --name my-tomcat tomcat
    

    You can then start with:

    docker start my-tomcat
    

    Port 8080 on your host will now send traffic to port 8080 of your container.

    You should be able to reach http://ip-of-vm:8080 in your browser.