Multi-stage deployment on docker
Entering the Docker world has been super exciting! From figuring out Dockerfiles to making images work together and making sure data stays safe, it’s been quite an adventure.
In today’s blog, let’s talk about making containers work even better. Think of Dockerfile layers like building blocks for images. To show you, let’s make a Python app, and these layers end up creating an image that’s quite big — around 1.01GB.
Now, making things faster when you use these containers is really important. We want them to start quickly and work smoothly. To do that, we’re going to use a trick called “Multistage build.”
Steps:-
Step 1: Clone the GitHub Repository
Step 3: Build the Docker Image
Step 4: Run the Docker Container and do checks imags size (docker images)
Step:6 Edit dockerfile (vim dockerfile)
Step 8: Build the Docker Image
Step 9: Run the Docker Container and see the size changes
Here’s how it works multistage :
Building Phase:
Start with a big python:3.9 block
Set the working space inside the container
Add our app code and install things it needs
Running Phase:
Switch to a smaller python:3.9-slim-buster block
Set up the working space again
Take only the important things from the big Building Phase
Add extra stuff our app needs, like Flask
Open a door (port 5000) so our app can talk to the outside world
After doing this, we rebuild our image using a command
: docker build -t multistage-flask-app .
What happens?
The image goes from being big, 1.01GB, to a much smaller 128M! Now, it’s ready to start up really fast.
Advantage of Distroless in Multistage Deploy:
Reduced Image Size:
Faster image pull times
Reduced storage requirements
Swift deployments, crucial in bandwidth-limited environments
Faster Build Times:
Less time to download and install layers
Improves the speed of the CI/CD pipeline
Improved Security:
Smaller attack surface
Fewer packages and dependencies reduce vulnerabilities
Efficient Resource Utilization:
Consumes fewer system resources (CPU, memory, disk space)
Valuable for scaling applications
Enhanced Network Performance:
Less data transfer across networks
Benefits microservices architectures
Streamlined Maintenance:
Fewer pre-installed packages simplify maintenance
Reduces the need for frequent updates
Top of Form
Thank you for exploring this blog with me! Wishing you joyous container crafting! 🚀🐳
I hope this is useful for you?
✅Reshare this with others so that it helps more people
✅Tag your colleagues and friends who you think will need this