Docker for DevOps Engineers (part-3)

Docker for DevOps Engineers (part-3)

Embarking on the Docker voyage for DevOps engineers! In our earlier section, we explored the process of crafting a Dockerfile and transmitting it to a repository. Presently, let's plunge into the realm of Docker Compose, unraveling key tasks to elevate your proficiency in Docker

Docker Compose

Docker Compose is a utility crafted to facilitate the definition and sharing of multi-container applications.

Through Compose, a YAML file can be generated to outline the services, allowing for the effortless deployment or dismantling of the entire setup with a single command.

What is YAML?

YAML, a data serialization language commonly employed for crafting configuration files, has dual interpretations.

Some view YAML as "yet another markup language," while others see it as "YAML ain't markup language," emphasizing its focus on data rather than documents.

The popularity of YAML in programming stems from its human-readable and easily comprehensible nature. Files using YAML adopt either the .yml or .yaml extension.

Let's jump into the tasks to understand this concept in more detail.

Task-1

Learn how to use the docker-compose.yml file, to set up the environment, configure the services and links between different containers, and also to use environment variables in the docker-compose.yml file.

  1. Environmental setup

    Solution - We create a docker-compose.yml file to define your services, networks, and other configurations. Here's a basic example:

    Here we have sets up an Nginx web server and a PostgreSQL database. The docker-compose up command will start both containers.

  1. In the preceding phase, we generated a fundamental docker-compose.yml file featuring two services:

    a. web server (nginx)

    b. database (postgres).

    To advance this configuration, we'll delve into service links and environment variables. Service links facilitate communication between services. Let's enhance our docker-compose.yml file to create a connection between the web service and the database service.

    The web service now has a links section, specifying that it's linked to the db service. This allows the web service to communicate with the db service by using the hostname db.

  1. Environment Variables

    Environment variables in Docker Compose enable you to configure services with dynamic values. Let's add an environment variable to the web service, specifying the welcome message.

Task-2

  • 1. Pull a pre-existing Docker image from a public repository (e.g. Docker Hub) and run it on your local machine.

    1. Inspect the container's running processes and exposed ports using the docker inspect command.

    2. Use the docker logs command to view the container's log output.

    3. Use the docker stop and docker start commands to stop and start the container.

    4. Use the docker rm command to remove the container when you're done.

I hope by accomplishing these tasks, we have broadened our understanding of Docker, delving into Docker Compose to proficiently manage multi-container applications and refining our ability to interact with Docker containers.

With our forthcoming articles, we'll delve into more advanced Docker concepts!

Thanks,

Kishor Chavan