Starting a Compose App
By the end of this exercise, you should be able to:
- Read a basic docker compose yaml file and understand what components it is declaring
- Start, stop, and inspect the logs of an application defined by a docker compose file
Preparing Service Images
Download the Dockercoins app from github:
PS: node-0 Administrator> git clone -b ee2.1 ` https://github.com/docker-training/orchestration-workshop-net.git PS: node-0 Administrator> cd orchestration-workshop-netThis app consists of 5 services: a random number generator
rng, ahasher, a backendworker, aredisqueue, and awebfrontend; the code you just downloaded has the source code for each process and a Dockerfile to containerize each of them.Have a brief look at the source for each component of your application. Each folder under
~/orchestration-workshop-net/contains the application logic for the component, and a Dockerfile for building that logic into a Docker image. We've pre-built these images astraining/dc_rng:1.0,training/dc_worker:1.0et cetera, so no need to build them yourself.Have a look in
docker-compose.yml; especially notice theservicessection. Each block here defines a different Docker service. They each have exactly one image which containers for this service will be started from, as well as other configuration details like network connections and port exposures. Full syntax for Docker Compose files can be found here: https://dockr.ly/2iHUpeX.
Starting the App
Stand up the app:
PS: node-0 orchestration-workshop-net> docker-compose upAfter a moment, your app should be running; visit
<node 0 public IP>:8000to see the web frontend visualizing your rate of Dockercoin mining.Logs from all the running services are sent to STDOUT. Let's send this to the background instead; kill the app with
CTRL+C, and start the app again in the background:PS: node-0 orchestration-workshop-net> docker-compose up -dCheck out which containers are running thanks to Compose:
PS: node-0 orchestration-workshop-net> docker-compose ps Name Command State Ports --------------------------------------------------------------------------------------------------- orchestration-workshop-net_hasher_1 dotnet run Up 0.0.0.0:8002->80/tcp orchestration-workshop-net_redis_1 redis-server.exe C:\Redis\ ... Up 6379/tcp orchestration-workshop-net_rng_1 dotnet run Up 0.0.0.0:8001->80/tcp orchestration-workshop-net_webui_1 node webui.js Up 0.0.0.0:8000->80/tcp orchestration-workshop-net_worker_1 dotnet run UpCompare this to the usual
docker container ls; do you notice any differences? If not, start a couple of extra containers usingdocker container run..., and check again.See logs from a Compose-managed app via:
PS: node-0 orchestration-workshop-net> docker-compose logs
Conclusion
In this exercise, you saw how to start a pre-defined Compose app, and how to inspect its logs. Application logic was defined in each of the five images we used to create containers for the app, but the manner in which those containers were created was defined in the docker-compose.yml file; all runtime configuration for each container is captured in this manifest. Finally, the different elements of Dockercoins communicated with each other via service name; the Docker daemon's internal DNS was able to resolve traffic destined for a service, into the IP or MAC address of the corresponding container.