Day 3/40 - Multi Stage Docker Build - Docker Tutorial For Beginners - CKA Full Course 2024

About this video

- **Introduction**: This is video number 3 in the CK series, focusing on Docker multi-stage builds. - **Previous Videos**: Covered Docker fundamentals and dockerized a sample application. - **Multi-Stage Build Purpose**: Reduces image size and improves performance by using multiple stages in the Docker build process. - **Current Video Focus**: Demonstrates how to use Docker multi-stage builds to reduce image size from over 200 MB (even with lightweight Alpine image). - **GitHub Repository**: Details and links provided in the description for viewers to follow along. - **First Video Content**: Explored Docker fundamentals, including issues before containers, Docker's solutions, differences between Docker and virtual machines, workflow, and architecture. - **Second Video Content**: Installed Docker desktop, cloned an application, wrote a Dockerfile, and explored commands like Docker build, tag, push, pull, run, images, and exec. - **Docker Multi-Stage Build Steps**: - Cloned an application and navigated into its directory. - Created a Dockerfile using `touch` command. - Defined stages: - First stage (`installer`) uses `node:18-alpine`, sets working directory, copies necessary files, installs dependencies with `npm install`, and runs `npm run build`. - Second stage (`deployer`) uses `nginx:latest`, copies only the build artifacts from the first stage into the appropriate Nginx directory. - **Benefits of Multi-Stage Builds**: Improved performance, security, smaller image sizes, isolation, and production readiness. - **Building the Image**: Used `docker build` to create the multi-stage image, resulting in a final image size of 1195 MB, which is efficient considering the complexity of the application. - **Cleanup Commands**: Demonstrated `docker image rm` to remove unused images and free up space. - **Running the Container**: Used `docker run` to start the container, exposing it on port 3000, and confirmed it was running with `docker ps`. - **Investigating Containers**: - Used `docker logs` to view container logs. - Used `docker exec` to interactively enter the container, inspect directories, and check logs. - Noted that only necessary static files were copied into the container, without unnecessary dependencies. - **Inspecting Containers**: Showcased `docker inspect` to get detailed information about the container’s configuration, including MAC address, IP, and ports. - **Best Practices**: - Discussed running containers as non-root users. - Encouraged viewers to research and comment on other Docker best practices. - **Conclusion**: Summarized the importance of following Docker best practices for production-grade projects and encouraged viewers to engage with comments and likes. Promised the next video soon.


Course: Certified Kubernetes Administrator Full Course For beginners | CKA 2025

This playlist contains the complete CKA series for beginners, based on the latest 2025 curriculum. It includes 40+ videos with hands-on demos, assignments, and exam-based scenarios. We will cover everything from the basics to the Advanced, including fundamental concepts such as Docker, containers, Docker storage and networking, DNS, etc.

View Full Course