Ramp Up Your Deployments with Docker Compose

Docker has quickly become one of the frontrunners when it comes to container management systems. It is easy to see why considering what it can do to boost a company's productivity.

When working with Docker, an applications' size can become quite large, complicating how you manage it. The solution to this issue is Docker Compose.

Introduction to Docker Compose

Docker Compose is Docker's tool used for defining and running multi-container applications. With Compose, you configure your application's services in a YAML file and then use that configuration to create all of the app's services.

You could think of docker-compose as an automated multi-container workflow. Docker Compose is a fantastic tool for development, testing, and CI workflows, as well as staging environments. The most popular features of Docker Compose that make it so effective, according to the Docker documentation, are:

  • Multiple isolated environments on a single host

  • Preserve volume data when you create containers

  • Only recreate containers that have changed

  • Variables and moving a composition between environments

Installing Docker Compose


Docker Engine needs to be installed on your device because Compose uses it. Compose works on Windows, Mac OS X, and Linux 64-bit. Docker Compose is surprisingly simple to set up. Docker Compose is available on desktop systems, with Docker Desktop for Mac and Windows. There are no additional steps required. You'll need to do the following on a Linux system:

  1. Install the Docker Engine

  2. Download Docker Compose:

3. Apply permissions to the binary:

4. Test the installation:

You can use Docker Compose with your Dockerfiles once you have it downloaded and running correctly. There are three basic steps to this procedure:

Docker Compose can is easily added to an existing project. If you already have Dockerfiles, open the Command Palette (Ctrl+Shift+P) and add Docker Compose files. Choose the Docker: Docker Compose Files to the Workspace, and, when prompted, select the Dockerfiles that you want to use.

When creating a Dockerfile, you can also include Docker Compose files in your Workspace. Like before, open your Command Palette and choose Docker: Add Docker Files to Workspace.

A prompt will appear, asking if you want to add any Docker Compose files. In both of these cases, the Compose extension will add the docker-compose.yml file to your Workspace.

Understanding Docker Compose file structure

Here is an example of the basic structure of a Docker Compose YAML file:

Let's take a look at a real-world example of a Docker Compose file and break it down step by step to help you understand everything. All of the clauses and keywords in this example are industry standard and generally used keywords.

These are all you need to start a development workflow. There are more advanced keywords for production use-cases; however, we will focus on the essential clauses.

Screen Shot 2021-04-05 at 11.52.51 AM.png


Important Docker Compose Commands

Let’s cover the most common Docker Compose commands that we can use with our files to know how to create docker-compose files.

Conclusion

We covered what Docker Compose is, how to install it, and how it’s file structure and commands work. There is much more to explore and learn to become an expert, for example, integrating this with Docker Swarm. To learn more about what you can do with Docker Compose, drop us a line @letsdothis@stonedoorgroup.com


About the Author

Amber Ernst is a Docker Certified Associate and Docker Accredited Instructor for Stone Door Group. Amber is a Docker and Kubernetes expert who currently teaches all courses in Mirantis’s official training catalog and is based in San Antonio, TX.

ABOUT STONE DOOR GROUP

Stone Door Group is a Hybrid Cloud and DevOps consulting company that delivers successful digital transformation projects in the private and public sectors. Stone Door Group is a team of leading experts in Hybrid Cloud and DevOps technologies. To speak with Amber and our team, send us an email at letsdothis@stonedoorgroup.com