Back to Blog Home

What Is Docker Compose

Jay Mishra| Docker | 7 months



 

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.

 

So some of the main features of Compose are:

 

Multiple isolated environments on a single host

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. 

 

Preserves Volumes Of Containers

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. 

 

Recreates Only Altered Containers

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. 

 

Variables and Extend

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.

 

 

What are the use cases for Docker Compose

 

Setting Up Development Environments

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.

 

Automated Testing For CI/CD

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. 

$ docker-compose up -d
$ ./run_tests
$ docker-compose down
 

 

Production Level Single Host deployments

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. 

 

How to Use Docker Compose:

  1. First You need a Dockerfile for your app to define it’s required environment
  2. Then you need to create a docker-compose.yml file which will have all the services that make up your app. 

       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 :

 

version: '3'
services:
  web:
    build: .
    ports:
    - "5000:5000"
    volumes:
    - .:/code
    - logvolume01:/var/log
    links:
    - redis
  redis:
    image: redis
volumes:
  logvolume01: {}

 

 

 

 



Join 1000+ People Who Subscribe to Weekly Blog Updates

Back to Blog Home