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.
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.
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.
Docker Compose is a tool that allows you to define and run multi-container Docker applications. It uses a YAML file called docker-compose.yml
to configure the services and links between different containers. In this file, you can specify the images to use, the ports to expose, and the environment variables for each service.
To run the docker-compose file we need to install it first by using
sudo apt-get install docker-compose
command.Clone the project and create a docker-compose.yaml file.
version : "3.9"
services:
my_web :
container_name : "django-todo-app"
build : .
ports :
- 8000:8000
mysql_db :
container_name : "django-db"
image : mysql:5.7
ports :
- 3306:3306
environment :
- MYSQL_ROOT_PASSWORD:"Shreya@123"
Run the docker-compose.yaml file in the background by using
docker-compose up -d
command.Check all the running containers by using
docker ps
command.
- Now the containers are up and we can check the application through the web URL.
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.
To run the container as a non-root user we use
sudo usermod -a -G docker $USER
command and thensudo reboot
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!!
~Shreya Gupta
Great initiative by the #trainwithshubham community. Thank you Shubham Londhe
#devops #90daysofdevops #linux #docker #dockercompose