In this lesson, youβll learn about: dockerizing a web app, writing Dockerfiles, and optimizing builds1. The Application Architecture (Real-World Example)This lab uses a simple microservices setup:Flask web application (frontend/API)
Redis (backend datastore)
Key idea:Each service runs in its own container
They communicate over a Docker network
π This mirrors real production systems (microservices architecture)2. Writing a Dockerfile from ScratchA Dockerfile is the blueprint for building an image in Docker.π§± FROM β Base ImageFROM python:2.7-alpineUses an official image
Alpine = very small size β faster builds & less storage
βοΈ RUN β Execute CommandsRUN mkdir /appRuns shell commands inside the image
Typically used for:Installing dependencies
Preparing the environment
π WORKDIR β Set Working DirectoryWORKDIR /appDefines where commands will run
Avoids hardcoding full paths everywhere
π¦ COPY β Add Files to ImageCOPY . .Copies your application code into the container
Includes:Source code
Requirements file
3. Build Optimization (Layer Caching)Docker builds images in layers
Order of instructions matters a lot
β
Optimized Approach:COPY requirements.txt . RUN pip install -r requirements.txt COPY . .Why?Dependencies donβt change often
Docker caches this layer
Rebuilds become much faster
4. Metadata with LABELLABEL maintainer="
[email protected]"Adds useful metadata:Author
Version
Description
π Helpful for team environments and production tracking5. Running the Application with CMDCMD ["python", "app.py"]Defines the default command when the container starts
In this case:Launches the Flask app on port 5000
6. How Everything Works TogetherBuild the image:docker build -t myapp .
Run the container:docker run -p 5000:5000 myapp
Access app:Open browser β localhost:5000
7. Key Concepts You Just LearnedHow to dockerize a real application
Core Dockerfile instructions:FROM, RUN, WORKDIR, COPY, LABEL, CMD
How layer caching speeds up builds
How services like Flask + Redis work together in containers
Key TakeawaysDockerfile = reproducible build recipe
Instruction order = performance optimization
Containers isolate services cleanly
This workflow is used in:DevOps
CI/CD
Cloud deployments
You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cybercode_academy