Hello, DevOps enthusiasts! ๐ You're doing an incredible job in the #90daysofdevops challenge. Today, we dive deeper into Docker with Docker Volumes and Docker Networks. Ready to explore? ๐
Introduction to Docker Volume
Docker Volumes are like external storage spaces for your containers. They allow you to persist data independently of the container lifecycle, meaning your data remains even if the container is removed. This is useful for databases or other data that you don't want to lose.
What are Docker Volumes?
Docker volumes are storage areas that can be mounted into one or more containers. They enable data persistence and sharing between containers.
Example Usage:
Storing database files
Sharing configuration files between containers
Why Use Docker Volumes?
Persistence: Data stored in volumes doesn't get deleted with the container.
Sharing: Multiple containers can access the same volume, facilitating data sharing.
For more details, check out this reference.
Introduction to Docker Network
Docker Networks allow containers to communicate with each other and with the host machine. This is crucial for multi-container applications, where different services (e.g., web server and database) need to interact.
What are Docker Networks?
Docker networks enable communication between containers by creating isolated virtual networks.
Example Usage:
Linking a web server container to a database container
Isolating development, testing, and production environments
Why Use Docker Networks?
Isolation: Separate environments for different stages of development.
Communication: Containers can easily communicate with each other.
Task 1 : Docker Volumes
Use the docker volume --create
command to create a dedicated volume in your local
Use the docker run --mount
command to create containers that read and write data to the same volume. This is where the fun begins! ๐ฐ๐ฉ
We went inside the container and created a secret.txt
file which is added t volume
After the old container is deleted and new container is formed still the volume secret-text.txt is attached to it.
Conclusion: Docker Volumes Unleashed! ๐
With Docker Volumes and Named Volumes in your toolkit, you're now equipped to efficiently manage and share data across containers like a pro. ๐ ๏ธ๐ณ
Task 2 : Create a multi-container docker-compose file that will bring UP and bring DOWN containers in a single shot
Step 1: Create an app.py
which is a flask app and its database is stored in MySQL
Step 2: Add all the requiremnets needed to be installed in requirement.txt
Step 3: Create a DockerFile for it
Step 4: Let's take a closer look at our docker-compose.yaml
file:
Step 5 : Do docker-compose up -d
Open port 5000 in your EC2 instance's Security Group inbound rules.
Access the Two-Tier App from your EC2 instance's public IP address:
http://public_ip:5000
.
You should see the beautiful output of your Two-Tier App! ๐
Access the MySQL container and log in to the MySQL database:
Use the docker-compose down
command to stop and remove all containers, networks, and volumes associated with the application
Conclusion
You've now explored Docker Volumes and Docker Networks, vital components for managing data and communication in Dockerized applications. By mastering these, you enhance your ability to build scalable and maintainable DevOps solutions. Keep going strong in your #90daysofdevops journey! ๐