Docker for Developers
上QQ阅读APP看书,第一时间看更新

Chapter 4: Composing Systems Using Containers

In the previous chapter, we created a server-side application using microservices architecture. The application was made up of five separate containers: three official images and two custom images. The official images were for MongoDB, Redis, and Mosca (MQTT).

For the most part, communication between containers is done via MQTT message passing. The subscriber container carries out the database Create, Read, Update, and Delete (CRUD) operations via the Node.js API for MongoDB and Redis. All of the relevant network ports are exposed on the development host, enabling the subscriber program to access the database servers at localhost (127.0.0.1) and both subscriber and publisher programs to access Mosca/MQTT at localhost, too.

In this chapter, we are going to discuss composing systems—specifically, Docker Compose.  We are also going to learn how to keep network access private so that services can be accessed from within our containers but not be accessible from the host. We will learn how we can share volumes in the filesystem between containers. There are alternatives to Docker Compose, and we will look at some of them.

We will cover the following topics in this chapter:

  • Introduction to Docker Compose
  • Using Docker local networking
  • Local volumes
  • Other composition tools

To recap, we have three official image containers for MongoDB, Mosca, and Redis. We have an additional two containers created for this book—publisher and subscriber microservices.  

The publisher microservice has been modified to present a form in a web browser. The fields in the form and the submit buttons allow us to exercise the various operations supported by the subscriber microservice:

Figure 4.1 – The form generated by our updated publisher program

You can choose which database to perform CRUD operations on. You can also set a value that is to be used for the List, Count, Add, and Remove operations. There is a button for each of the CRUD operations, as well as a Flush button, which removes all the records from the selected database. The return value/result of the operation is shown beneath the form under the Result heading.