# Day 18 Task: Docker for DevOps Engineers

## Docker Compose

* Docker **Compose** is a tool that was developed **to help define and share multi-container** applications.
    
* With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.
    

## What is YAML?

* YAML stands for **Y**et **A**nother **M**arkup **L**anguage
    
* YAML is a data serialization language that is often used for writing configuration files. Depending on whom you ask, YAML ain’t markup language (a recursive acronym), which emphasizes that YAML is for data, not documents.
    
* YAML is a popular programming language because it is human-readable and easy to understand.
    
* YAML files use a .yml or .yaml extension.
    

## 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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682932073805/8759548a-ebcb-4886-943c-43d4b1a78225.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682932091695/34ae1ae5-204c-4600-b5cd-992ed91bc5c3.png align="center")

Docker-compose.yml

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682985583218/3ed84e2f-52af-4283-a9b8-967763814cf0.png align="center")

environment variables in the docker-compose.yml file

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682985807886/3ee1f697-faf0-4ebf-8493-77ca5787bc60.png align="center")

## 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 the user permission to docker). Make sure you reboot the instance after permitting the user.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682990907960/30cfd0c2-3934-4058-b26a-45018f4c9291.png align="center")
    
* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682990734845/66300c23-4ddb-4e0f-9db9-b6a0d2d303d8.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682990713732/c61acf7f-7855-47dd-88aa-239468b4e168.png align="center")
    
* Inspect the container's running processes and exposed ports using the docker inspect command.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682991678594/267f4de7-5726-48da-90f5-cfac4cf01ba6.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682991333569/d37f8327-a15a-4ea8-a989-6be31ab2aaff.png align="center")
    
* Use the docker logs command to view the container's log output.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682991719323/5548d341-541e-440d-a890-953ff1e3ca36.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682991406066/21815d9f-14a3-4c2d-bc9a-f4cf326f6310.png align="center")
    
* Use the docker stop and docker start commands to stop and start the container.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682991758311/acdba0bb-d4e5-40ba-a978-6baa38aa4e84.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682991482460/c066f2d2-4f34-4ffc-ad74-0e649997b5bf.png align="center")
    
* Use the docker rm command to remove the container when you're done.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682991783111/7d7a7a44-f39c-463e-b0e1-2f7dd0f84ec5.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682991583445/284eb11f-564e-4835-b6bb-7b8e17e89332.png align="center")
    

## How to run Docker commands without sudo?

* Make sure docker is installed and the system is updated (This is already been completed as a part of previous tasks):
    
* sudo usermod -a -G docker $USER
    
* Reboot the machine.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682991950304/8ddd6ded-37dc-4fe6-9259-dcef24a2b530.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1682991002915/ec3242c6-2cca-4917-b227-7ce7a5d93477.png align="center")
    

Happy Learning :)

Mohammed Muqafamuddin.
