Concept of Docker Compose

Last updated on Sep 17 2022
Neha Warghade

Table of Contents

Concept of Docker Compose

Docker – Compose

Docker Compose is employed to run multiple containers as a single service. For example, suppose you had an application which required NGNIX and MySQL, you could create one file which would start both the containers as a service without the need to start each one separately.

In this blog, we will see how to get started with Docker Compose. Then, we will look at how to get a simple service with MySQL and NGNIX up and running using Docker Compose.

Docker Compose ─ Installation

The subsequent steps need to be followed to get Docker Compose up and running.

Step 1 − Download the necessary files from github using the subsequent command −

curl -L “https://github.com/docker/compose/releases/download/1.10.0-rc2/dockercompose   -$(uname -s) -$(uname -m)” -o /home/demo/docker-compose

The above command will download the latest version of Docker Compose which at the time of writing this article is 1.10.0-rc2. It will then store it within the directory /home/demo/.

doc 69

Step 2 − Next, we need to provide execute privileges to the downloaded Docker Compose file, using the subsequent command −

chmod +x /home/demo/docker-compose

doc 70

We can then use the subsequent command to see the compose version.

Syntax

docker-compose version

Parameters

  • version − This is employed to specify that we want the details of the version of Docker Compose.

Output

The version details of Docker Compose will be displayed.

Example

The subsequent example shows how to get the docker-compose version.

sudo ./docker-compose -version

Output

You’ll then get the subsequent output −

doc 71

Creating Your Primary Docker-Compose File

Now let’s go ahead and create our primary Docker Compose file. All Docker Compose files are YAML files. You can create one using the vim editor. So execute the subsequent command to create the compose file −

sudo vim docker-compose.yml

doc 72

Let’s take a close look at the various details of this file −

  • The database and web keyword are employed to define two separate services. One will be running our mysql database and the other will be our nginx web server.
  • The image keyword is employed to specify the image from dockerhub for our mysql and nginx containers
  • For the database, we are using the ports keyword to mention the ports that need to be exposed for mysql.
  • And then, we also specify the environment variables for mysql which are required to run mysql.

Now let’s run our Docker Compose file using the subsequent command −

sudo ./docker-compose up

This command will take the docker-compose.yml file in your local directory and start building the containers.

doc 73

Once executed, all the images will start downloading and the containers will start automatically.

doc 74

And when you do a docker ps, you can see that the containers are indeed up and running.

doc 75

 

So, this brings us to the end of blog. This Tecklearn ‘Concept of Docker Compose’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Docker and build a career in DevOps domain, then check out our interactive, Containerization using Docker Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/containerization-using-docker/

Containerization using Docker Training

About the Course

Tecklearn has specially designed this Containerization using Docker Training Course to advance your skills for a successful career in this domain. his Docker training online course will help you learn Docker containerization, running Docker containers, Docker image creation, Dockerfile, Docker orchestration, security best practices and more through hands-on projects and case studies. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Docker.

Why Should you take Containerization using Docker Training?

  • Average salary of Docker Expert is $110k – Indeed.com
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.
  • Intuit, PayPal, Splunk, Uber & many other MNC’s worldwide use Docker across industries

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Containerization using Docker – Part 1

  • Introduction to Docker
  • Understanding Docker Lifecycle
  • Docker Architecture
  • Components of Docker Ecosystem
  • Common Docker Operations
  • Committing changes in a Container
  • Hands On

Containerization using Docker – Part 2

  • Building Custom Docker Images
  • Docker Image
  • Introduction to Docker Swarm
  • Deploying a 2-Node Cluster using Docker Swarm
  • Hands on

 

0 responses on "Concept of Docker Compose"

Leave a Message

Your email address will not be published. Required fields are marked *