# 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 is a data serialization language that is often used for writing configuration files. Depending on whom you ask, YAML stands for yet another markup language or 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**

1. ### 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.
    
    Create docker-compose.yml
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750090806094/675abe28-ebd9-46fa-a8f8-127ddb9cd9df.png align="center")
    
    Use docker-compose.yml
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750090846691/6e95a79d-f1f3-4332-b656-ef918d4dd4e7.png align="center")
    
    # **Task 2**
    
    1. ### 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.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750090967169/8cd3bc74-d2de-44fe-ab57-07e60841bc9a.png align="center")
        
    2. ### Inspect the container's running processes and exposed ports using the docker inspect command.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750091017428/a79dea58-b8f5-46b2-9f26-a30fe34738fe.png align="center")
        
    3. ### Use the docker logs command to view the container's log output
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750091070688/3fdfe214-083d-49c6-8d0d-0b061ba73adc.png align="center")
        
        4. ### Use the docker stop and docker start commands to stop and start the container.
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750091127852/f42dfd47-2d7b-4ced-8f23-a355bafc653d.png align="center")
            
        5. ### Use the docker rm command to remove the container when you're done.
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750091192797/7bd3bb1a-8c92-4d77-809d-72562f2f5948.png align="center")
            
            # **🔹How to run Docker commands without sudo?**
            
            * Make sure docker is installed and system is updated (This is already been completed as a part of previous tasks):
                
            * sudo usermod -a -G docker $USER
                
            * Reboot the machine.
