# Day 18 Task: Docker for DevOps Engineers -Part2

**Dear Engineers in today topic we will learn the Docker for the DevOps Engineers Part-2**

***Docker compose is a tool used for the developed to help define and share multiple container applications.With the help of docker compose command we can create a yaml file to determine the services with one single command.***

***What is YAML?***

***Yaml is a popular programming language because it is human readbale and easy to understand YAML files use .yml or .yaml extension***

### **Task-1**

***Docker compose- it is a tool that defining the running multi-container Docker applications. with the help of compose you use a yaml file to configure your applications.***

***Install the docker-compose***

***Syntax:- sudo apt-get install docker-compose -y***

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQHOHI4BjYTwpQ/article-inline_image-shrink_400_744/0/1682699420966?e=2147483647&v=beta&t=brf0TBGQMhyyr639IvlcHTfQtYkfdzydk3btVlLEdJA align="left")

sudo apt-get install docker-compose -y Diagram.

***Step 2 : Create a docker-compose.yml file inside project folder***

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGd5wAVYcBa6w/article-inline_image-shrink_400_744/0/1682699784198?e=2147483647&v=beta&t=vDxSKKfiCozlnuAKDU1xJYwJVQl9a8dFCltThiUdl-I align="left")

Docker compose yaml file Diagram.

* ***Version:3.3 it denotes we are using the version 3.3 docker compose.***
    
* ***Services: it wlill defines the different containers we will create.***
    
* ***build: keyword specifies the location of our dockerfile and represents the directory.***
    
* ***image:specify the image from docker hub for mysql containers***
    
* ***ports: keyword used for the ports that need to be exposed.***
    
* ***environment variables: for mysql which are required to run mysql.***
    
* ***Step 3: Run docker-compose.yml file***
    

***docker ps or docker-compose ps command list all the containers in the current docker-compose file.***

### **Task-2**

***1 Pull a pre-existing docker image form a public repository (eg docker hub)***

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGIhP9yc-Pn9A/article-inline_image-shrink_400_744/0/1682700492817?e=2147483647&v=beta&t=Z7Gc5vb6VAIDPzMxTaHuJTNd18jE62qX8vVKKamYKNg align="left")

docker pull nginx:alpine

***for running container as a non-root user, use command usermod to give user permission to docker***

***syntax: sudo usermod -a -G docker $USER***

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQG1hUu-ZPVpsA/article-inline_image-shrink_400_744/0/1682700831726?e=2147483647&v=beta&t=PLTK6enKQPqiYCYYwI_3qJc-vDn5wtzzAUIuncFczzY align="left")

sudo usermod -a -G docker $USER

***2 Inspect the container running process and exposed ports using the docker inspect command***

***syntax:- docker inspect &lt;container\_name or id&gt;***

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQHhGiP2KY1iSA/article-inline_image-shrink_400_744/0/1682701044280?e=2147483647&v=beta&t=5WX8pYh2gNfnxbk_BU3fRyHLB0U8_vzOs9Ltc3fgUKU align="left")

docker inspect &lt;container\_name or id&gt; Diagram.

***3 Use the docker logs command to view the docker container log output***

***Synatx: sudo docker logs &lt;container\_name or ID&gt;***

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQHSBlW1WSOHIg/article-inline_image-shrink_400_744/0/1682701644193?e=2147483647&v=beta&t=yJrSX5I-IXuuwZYaqFJI_L6m2G6Pq_HtHYyh77pTvFk align="left")

sudo docker Containers logs Diagram

***4 Use the docker stop and docker start commands to stop and start the container.***

***syntax: sudo docker stop &lt;container-name or ID&gt;***

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQHPfleDr9h8cw/article-inline_image-shrink_400_744/0/1682701666960?e=2147483647&v=beta&t=Xd7cF-xry20wFN8CoQZbjTFIJqsl-D4IyJpqmc6X234 align="left")

sudo docker stop &lt;container-name or ID&gt;

***Syntax: sudo docker start &lt;container-name or ID&gt;***

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQGZazTjtqUHUQ/article-inline_image-shrink_400_744/0/1682701689332?e=2147483647&v=beta&t=yhXdAtdfEWwDriOSvgptr7yLAZmdWiGoAYOqVW2emnQ align="left")

sudo docker start &lt;container-name or ID&gt; Diagram.

***5 use the docker rm command to remove the container when you are done docker rm. remove one or more containers.***

***Syntax: sudo docker rm &lt;container\_name or ID&gt;***

![No alt text provided for this image](https://media.licdn.com/dms/image/D5612AQEBGb95LwfKww/article-inline_image-shrink_400_744/0/1682701771625?e=2147483647&v=beta&t=nCIAQjGPV9Ul2c-wwBiYMNOrAlrNb4H0fCON1CBC3aY align="left")

sudo docker rm &lt;container\_name or ID&gt; Diagram.

***Thank you for reading the article!!***
