Docker networking
Most applications these days do not run in isolation; they need to communicate with other systems over the network. If we want to run a website, web service, database, or cache server inside a Docker container, we need to first understand how to run a service and expose its port to other applications.
Running services
Let's start with a simple example and run a Tomcat server directly from Docker Hub, as follows:
$ docker run -d tomcat
Tomcat is a web application server whose UI can be accessed by port 8080
. Therefore, if we installed Tomcat on our machine, we could browse it at http://localhost:8080
. In our case, however, Tomcat is running inside the Docker container.
We started it the same way we did with the first Hello World
example. We can see that it's running, as follows:
$ docker ps CONTAINER ID IMAGE COMMAND &...