Day 20 Task : Docker compose
Docker Compose is a tool that allows you to define and manage multi-container Docker applications using a simple YAML file called docker-compose.yml
. With Docker Compose, you can easily set up, run, and manage complex applications involving multiple services like web servers, databases, caches, and more, all configured in one place.
Key Features of Docker Compose
Multi-Container Deployment: Define multiple services (containers) that make up your application in a single YAML file.
Networking: Automatically creates networks for your containers, allowing them to communicate with each other easily.
Volumes: Manage data persistence by defining volumes for your containers.
Environment Management: Easily set environment variables for your containers, making configuration management straightforward.
Scaling Services: Easily scale services up or down with a single command.
Basic Docker Compose Workflow
Define Your Application in
docker-compose.yml
: Create a YAML file that specifies your services, networks, and volumes.Build and Start Services: Use Docker Compose commands to build, start, stop, and manage your services.
Now lets create a docker compose
Step 1: Install docker compose in your system as shown in the below image
Step 2 : Here we are taking the code from github .
Step 3 : Here we have docker-compose.yaml where we will write the yaml file to build and run the docker conatiner at a time.
Step 4 : The docker-compose build
command is used to build Docker images specified in your docker-compose.yml
file. This command reads the build configurations, such as Dockerfiles and contexts, and creates Docker images for the services defined in the file.
Step 5:The docker-compose up
command is used to start and run the services defined in your docker-compose.yml
file. This command builds (if necessary), creates, and starts the containers as per the configurations specified in the Compose file. It's one of the most common and powerful commands in Docker Compose, enabling you to quickly spin up your entire application stack.
Step 6 :The docker-compose ps
command provides a snapshot of the current status of the containers defined in your docker-compose.yml
file. It helps you see which containers are running, their names, and their ports.
Step 7:The docker-compose logs
command is used to view the logs for services defined in your docker-compose.yml
file. This command provides real-time or historical log data from your containers, which is essential for debugging and monitoring the behavior of your applications.
THANK YOU FOR READING!
Do follow me on LinkedIn for further blogs.
linkedin.com/in/manasa-j-03b633238
Subscribe to my newsletter
Read articles from Manasa J directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by