Day 18 of #90DaysOfDevOps

Day 18 of #90DaysOfDevOps

Docker-Compose

Docker Compose is a tool for running multi-container applications on Docker defined using the Compose file format. A Compose file is used to define how one or more containers that make up your application are configured. Docker Compose file is written in YAML format. Once you have a Compose file, you can create and start your application with a single command: docker compose up.

What is YAML?

YAML is a human-readable data serialization language that is often used for writing configuration files. YAML stands for yet another markup language. YAML is a popular programming language because it is designed to be easy to read and understand. YAML files use a .yml or .yaml extension, and follow specific syntax rules.

Creating Your First Docker-Compose File

vi docker-compose.yml

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

  • The database and web keyword are used 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 used 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 nginx.

  • 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 following command −

docker-compose up -d

This command will take the docker-compose.yml file in your local directory and start building the containers. Once executed, all the images will start downloading and the containers will start automatically.

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