1. Lessons from pingme
We have an application called pingme that we will be using to explore docker
Pingme came about when I was trying to find a way to demonstrate docker containers at work and to better understand docker networking
pingme
Pingme is a simple web application that exposes three ReSTful endpoints
ReSTful endpoint | Purpose |
---|---|
/api/status | Returns “Healthy” if the app is running successfully |
/api/time | Returns the current local time in the format [pingMe time: 13:09:49.602311600] |
/api/timefromhelper | Returns the time from a remote pingme application in the format [pingMe time: 13:09:49.602311600] If this pingme cannot connect to the remote pingme, it returns the current local time in the format **[pingMe time: 13:09:49.602311600] |
Use pingme to learn how container-to-container works. It works by simply returning the local time in this format [pingMe time: 13:09:49.602311600].
Possible configurations are
Get docker image
Get source code
Standalone mode - Run it by typing
docker run -d -p 8080:8080 pingme
From your browser hit any of the following endpoints
HTTP://localhost:8080/api/status
This returns the health status of the appHTTP://localhost:8080/api/time
This returns the local time in the following format [pingMe time: 13:09:49.602311600]
Paired mode
Paired mode was introduced because we were trying to run the same application twice. It’s a quick and simple piece of code. We didn’t want to get into anything elaborate. And we wanted something that would work with environment variables so that that we could demonstrate these with docker-compose and kubernetes.
We wanted to boot the app twice, each running on a different port. The port would be modified from the default port of 8080 by the use of an environment variable, one instance using the environment variable and the other instance not using it. Docker containers are ideal for testing out your architecture because each container can choose which ports to expose to the outside world.
HTTP://localhost:8080/api/timefromhelper
This will either return the time from another pingme (remote) that this pingme (local) is connected to if the environment variable PINGME_ENDPOINT has been specified. Otherwise, it returns the local time in the following format **[pingMe time: 13:09:49.602311600] (notice the two Asterix preceding the time.
PINGME_ENDPOINT: Practice setting this to the remote pingme sever to get a better understanding of how docker container to container works.
For paired mode to work, you have to set up container-to-container communications, execute the following sequence of events
docker run -d -p 8080:8080 --name pmr pingme
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' pmr
This will print out the pmr container's IP address within the default bridge subnet.
docker run -d -p 8090:8080 --name pml -e PINGME_ENDPOINT=<http://<pmr> IP address>:8080 pingme
If you have entered the details correctly, you should be able to type HTTP://localhost:8090/api/timefromhelper
and get the time from pingme running on localhost:8080
.
Play around with the IP addresses and port numbers to better understand what's going on. Also, docker exec into pml and use ping
and wget
to try test communicating with pmr.