Table of contents
- Introdcution
- What's Docker Compose?
- Understanding YAML:
- Task-1: Using Docker Compose for Environment Setup
- Task-2: Managing Containers with Docker Compose
- Hurray! Our quiz app is successfully running using Docker Compose, and our database is also working smoothly. π
- Conclusion
- Thanks for reading! π Happy reading!
This is#90DaysofDevopschallenge under the guidance ofShubham Londhesir.
Introdcution
- In the journey of DevOps, we've advanced from creating Docker files and pushing them to repositories. Today, we venture into Docker Compose, a tool that simplifies defining and sharing multi-container applications.
What's Docker Compose?
Docker Compose is like a conductor for your containers. It orchestrates how multiple containers work together. You define all the services your application needs in a YAML file, like databases, web servers, or APIs. Then, with just one command, Docker Compose starts all these services together, making it easy to develop and test complex applications locally.
To explore further, let's understand YAML:
Understanding YAML:
YAML is a way to write down structured data in a human-readable format. It's like a blueprint for your configuration settings. YAML stands for "YAML Ain't Markup Language," which is a funny way of saying that it's not meant for formatting documents like HTML or XML. Instead, it's great for defining settings and configurations for your applications. YAML files use indentation and key-value pairs to organize data, making them easy to read and write.
In Docker Compose, you use YAML files to describe your application's services, including things like which Docker image to use, what ports to expose, and how different containers should communicate with each other.
Task-1: Using Docker Compose for Environment Setup
Setting up the Environment:
Create a docker-compose.yml
file in your project directory.
Configuring Services:
Define services in the docker-compose.yml
file:
version: '3'
services:
web:
image: supriya279/quiz-app-new1:latest
ports:
- "5000:5000"
restart: always
environment:
- FLASK_APP=app.py
- FLASK_ENV=development
db:
image: mysql:latest
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=test@123
The web
service runs your quiz app image, exposing port 5000. The db
service runs a MySQL database, exposing port 3306.
Running Docker Compose:
To start the services defined in the docker-compose.yml
file, run:
docker-compose up -d
The -d
flag runs the services in detached mode, meaning they run in the background.
Running Docker Commands without sudo:
Ensure Docker is installed and the system is updated. Grant Docker permissions to the current user by running:
sudo usermod -a -G docker $USER
Remember to reboot the machine after granting permissions.
Task-2: Managing Containers with Docker Compose
To perform the actions specified in Task-2 using Docker Compose:
Inspect Container's Running Processes and Exposed Ports:
docker-compose ps
Hurray! Our quiz app is successfully running using Docker Compose, and our database is also working smoothly. π
View Container's Log Output:
docker-compose logs web docker-compose logs db
Stop and Start the Container:
docker-compose stop web docker-compose start web
Remove the Container:
docker-compose down
This command will stop and remove all containers defined in the
docker-compose.yml
file.
Conclusion
In conclusion, Docker Compose proves to be a valuable tool in the DevOps arsenal, making it easier for engineers to manage complex application setups. As we explore its features further, we discover more ways to efficiently handle containers and deploy applications.