Docker compose is a tool to run and manage applications which have multiple Docker containers. It uses a YAML file to configure and provision all the services which will be used by your app and then help them get started by a single command.
On the basis of the name of the project, compose can create multiple isolated environments. So you can keep multiple environments for different branches running on your local host.
Compose is pretty smart about how it preserves and manages volumes used by services. It copies the volumes from the older container to the new containers preserving the data you’ve created.
Compose keeps a stored caches of the configuration to create a container only recreates containers if that config is changed making it super fast to change your environment.
Compose file supports variables which can used to infuse logic like setting up different environments for different users and help in customisation. It also has ‘extend’ wherein a compose file can extend other compose files.
When doing the actual development, developers need to keep an entire step wise documentation for setting up the development environment just to get started. Docker Compose can solve lot of these issues by replacing all of those error prone manual steps by simple Compose file which can setup all the required service dependencies like dbs, caches, APIs etc with a single docker-compose up command.
When your team is doing CI/CD or Continuous Deployment or Continuous Integration, you need to run a set of automated test suites on the fly. So you can use compose to create those isolated testing environments.
Usually Docker Compose is used for the development and testing part, but increasingly it is being built to handle more of production level workflows as well. You can now deploy a remote docker engine which can be a single instance provisioned by docker machine or it can be the whole swarm cluster.
3. That’s it, just run ‘docker-compose up’ commands and compose will get everything up and running under the hood for your app.
A docker-compose.yml sample file :