Docker Compose:
Docker Compose is used to run multiple containers as a single service. For example, suppose you had an application which required NGNIX and MySQL, you could create one file which would start both the containers as a service without the need to start each one separately.
For example:
If you have an application that requires an NGINX server and Redis database, you can create a Docker Compose file that can run both the containers as a service without the need to start each one separately.
Now, you might be thinking that Docker Compose is quite similar to Docker Swarm, but that’s not the case. Here are some of the differences between Docker Compose and Docker Swarm:
Basic Commands in Docker Compose:
Stop all services: Docker Compose down
Install Docker Compose using pip: pip install -U Docker-compose
Check the version of Docker Compose: Docker-compose-v
Run Docker Compose file: Docker-compose up -d
List the entire process: Docker ps
Scale a service - Docker Compose up -d -scale
Use YAML files to configure application services - Docker Compose.yml
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.
This is a very basic example of a YAML file:
#Comment: This is a supermarket list using YAML
#Note that - character represents the list
---
food:
- vegetables: tomatoes #first list item
- fruits: #second list item
citrics: oranges
tropical: bananas
nuts: peanuts
sweets: raisins
TASK1:
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.
Docker compose is nothing but everything we can write under same YAML file like:
-Docker Build
-Port expose
-Docker run
and at a time same file we can create multiple containers like below.
In other words,we can say split docker build and docker run commands and create YAML file syntax.
Here environment variables:MYSQL User and Password
-Services contain the number of containers or applications the user wants to run.
-Ports refer to the particular application being exposed to an external URL.
-Environment passes the credentials or data to be passed to the container.
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.
Use the docker rm command to remove the container when you're done.
Thank you for reading!! Hope you find this helpful.
#day18#90daysofdevops#devopscommunity
Always open for suggestions..!!
Thank you Shubham Londhe.