Book Image

Learning Docker - Second Edition

By : Vinod Singh, Pethuru Raj, Jeeva S. Chelladhurai
Book Image

Learning Docker - Second Edition

By: Vinod Singh, Pethuru Raj, Jeeva S. Chelladhurai

Overview of this book

Docker is an open source containerization engine that offers a simple and faster way for developing and running software. Docker containers wrap software in a complete filesystem that contains everything it needs to run, enabling any application to be run anywhere – this flexibily and portabily means that you can run apps in the cloud, on virtual machines, or on dedicated servers. This book will give you a tour of the new features of Docker and help you get started with Docker by building and deploying a simple application. It will walk you through the commands required to manage Docker images and containers. You’ll be shown how to download new images, run containers, list the containers running on the Docker host, and kill them. You’ll learn how to leverage Docker’s volumes feature to share data between the Docker host and its containers – this data management feature is also useful for persistent data. This book also covers how to orchestrate containers using Docker compose, debug containers, and secure containers using the AppArmor and SELinux security modules.
Table of Contents (13 chapters)

Testing your code inside Docker

In this section, we will take you through a journey in which we will show you how TDD is done using stubs and how Docker can come in handy when developing software in the deployment equivalent system. For this purpose, we take a web application use case that has a feature to track the visit count of each of its users. For this example, we use Python as the implementation language and redis as the key-value pair database to store the users hit count. Besides, to showcase the testing capability of Docker, we limit our implementation to just two functions—hit and getHit.

All the examples in this chapter use Python 3 as the runtime environment. The Ubuntu 16.04 installation comes with Python 3 by default. If you don't have Python 3 installed on your system, refer to the respective manual to install Python 3.

As per the TDD practice, we start by adding unit test cases for the...