Running multi-container applications with Docker Compose

Services rarely run in isolation. A microservice usually connects to a data store of some kind, and could have other runtime dependencies. In order to work on a microservice, it's necessary to run it locally on a developer's machine. Requiring engineers to manually install and manage all the runtime dependencies of a service in order to work on a microservice would be impractical and time consuming. Instead, we need a way to automatically manage runtime service dependencies.

Containers have made services more portable by packaging the runtime environment and configuration with the application code as a shippable artifact. In order to maximize the benefits of using containers for local development, it would be great to be able to declare all the dependencies and run them in separate containers. This is what Docker Compose is designed to do.

Docker Compose uses a declarative YAML configuration file to determine how an application should be executed in multiple containers. This makes it easy to quickly start up a service, a database, and any other runtime dependencies of the service in a way that makes local development especially easy.

In this recipe, we'll follow some of the steps from the previous recipe to create a Dockerfile file for the authentication-service project. We'll then create a Docker Compose file that specifies MySQL as a dependency of the authentication-service. We'll then look at how to configure our project and run it locally with one container running our application and another running a database server.