Docker tomcat not accessible from browser

2019-05-31 18:45发布

问题:

I have started a container with some ports open and tries to access the web interface of Tomcat from browser but it's not working.

1)docker run -ti --rm --name server -p 3456:5678 tomcat:8.0 // not working with localhost:3456
2)docker run -ti --rm --name server -expose 8080 tomcat:8.0 //not working localhost:8080
3)docker inspect server // to see the ip:port and tried to access using it as well but no luck

I am using CentOS7 with docker instaled.

Thanks

回答1:

It is very simple:

  1. is not working because you are binding to container port 5678 which is not used by tomcat (see EXPOSE commands in Dockerfile)
  2. is not working because you did not bind to a host port (-p is missing)

This works:

docker run -ti --rm --name server -p 9090:8080 tomcat:8.0

Open localhost:9090 in your browser.



标签: tomcat docker