Day 18 Docker Project for DevOps Engineers (Part-2)

Day 18 Docker Project for DevOps Engineers (Part-2)

Day 18 of #90daysofdevops

Hey Techies! Welcome to this blog

In this blog, we are going to start the Docker Project for DevOps Engineers (Part - 2)

Docker Compose

Docker Compose is a tool that helps you define and share multi-container applications. Docker Compose is used to run multiple containers as a single service. For example, suppose you had an application that required NGNIX and MySQL, you could create one file that would start both containers as a service without the need to start each one separately. It allows you to use a YAML file to configure your application’s services. Compose works in all environments; production, staging, development, testing, as well as CI workflows.

What is YAML?

YAML stands for "YAML Ain't Markup Language." It's a human-readable data serialization language often used for configuration files and data exchange between systems. YAML is commonly used in configurations for software applications, infrastructure as code (like Kubernetes or Ansible), and other scenarios where data needs to be organized in a readable and easy-to-understand format.

YAML's structure is defined by indentation and relies on whitespace indentation to represent data hierarchy, making it quite intuitive for humans to read and write. It uses key-value pairs, lists, and nested structures to represent data.

Here's an example of YAML syntax:

key1: value1 key2:

  • item1

  • item2

  • item3 key3: subkey1: subvalue1 subkey2: subvalue.

    YAML is often preferred for its simplicity, readability, and ability to represent complex data structures concisely, which makes it popular for configuration purposes in various applications and systems.

Docker Benefits

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.

Sample yaml file:

version: "3"
services:
    web:
      image: nginx
      ports:
        - 8080:80
    database:
        image: redis

For docker-compose we need a docker network, one backend (could be any database) and a frontend (could be any application)

docker-compose up -d #to build the image locally and run the image.

docker-compose down #to stop the container and network.

Task 2

  • Pull a pre-existing Docker image from a public repository (e.g. Docker Hub) and run it on your local machine. Run the container as a non-root user (Hint- Use usermod command to give user permission to docker). Make sure you reboot instance after giving permission to user.

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

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

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

    docker start <container_id>

    docker start <container_id>

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

    Thank you so much for taking the time to read till the end! Hope you found this blog informative and helpful.

    Feel free to explore more of my content, and don't hesitate to reach out if need any assistance from me or in case of you have any questions.

    Happy Learning!

    ~kritika :)

    Connect with me: linkedin.com/in/kritikashaw