Day 18: Docker for DevOps Engineers: Part-2

Day 18: Docker for DevOps Engineers: Part-2

#90daysofdevops

·

3 min read

🔸What is 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.

🔸Docker Compose Commands

The basic commands that bring hand on experience in docker-compose are:

  • Docker Compose up: Command used to start all the services of the container.

  • Docker Compose down: This syntax is used to stop all the services that were started.

  • Docker_compose_v: To check the version of docker-compose, we use this command.

  • Docker ps: This command is used to bring out the whole process of Docker.

  • Docker Compose.yml: This command is used to configure application services using YAML files.

  • Docker-compose up -d: Used to run a Docker-Compose file.

  • Docker Compose up -d -scale: Used to scale the service of the container.

  • pip install -U Docker-compose: Command used to install Docker Compose using pip.

Using Docker-Compose is essentially a three-step process:

  1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere.

  2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.

  3. Run docker compose up and the Docker compose command starts and runs your entire app. You can alternatively run docker-compose up using Compose standalone(docker-compose binary).

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

🔸The syntax of the YAML file is:

keyword: argument

🔸Example of a YAML file:

name: Vishesh ghule
age: 19
email: visheshghule2@gmail.com

đź’ŽTasks:

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.

A) Created a directory containing a web-application from github

https://github.com/LondheShubham153/react_django_demo_app.git

B) Created a docker-compose.yml file

version: '3.9'
services:
 web:
 build: .
 ports:
 — “8001:8001”

C) Started the container using the below command

sudo docker-compose up -d

D) If we need to down or close the application then need to use the below command.

sudo docker-compose down

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.

Pulled a Nginx image and Run the container.

docker pull nginx
docker run -d -p 8080:80 nginx

sudo usermod -aG docker ubuntu
sudo reboot

  • Inspect the container’s running processes and exposed ports using the docker inspect command.
sudo docker inspect 0804eb0755fb

  • Use the docker logs command to view the container’s log output.
sudo docker logs 0804eb0755fb

  • Use the docker rm command to remove the container when you’re done
sudo docker rmi nginx -f
  • Run the container in demeon mode
sudo docker run -d -p 8082:80 nginx
sudo usermod -aG docker ubuntu
sudo reboot


Thanks for reading to the end; I hope you gained some knowledge.❤️🙌

Linkedln

Twitter

Github

Â