Skip to content

About

These are different Scenarios for working with Docker with their Commands

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

🐳 Docker Practical — Complete Scenario Guide

This is the official README file for my Docker practical series — a complete, 100% reproducible walkthrough of 8 Docker scenarios, each designed to build a deeper understanding of how containers, images, volumes, and multistage builds work in real-world development.

These scenarios were originally prepared by Dr. Priyank Thakkar, and I’ve implemented each one step-by-step to strengthen my grasp on Docker and MLOps fundamentals.

If you want to run a Dockerfile or a Docker Compose file, all the necessary links and commands have been provided inside the practical document included in this repository.


🎯 Aim of the Practical

To gain a full understanding of Docker concepts by:

  • Creating containerized web and database applications.
  • Building optimized images with multi-stage builds.
  • Using Docker Compose for orchestration.
  • Persisting container data via Docker Volumes.
  • Practicing import/export, save/load, and conditional deployments.

📂 Repository Structure

├── Scenario_1/
├── Scenario_2/
├── Scenario_3/
├── Scenario_4/
├── Scenario_5/
├── Scenario_6/
├── Scenario_7/
├── Scenario_8/
├── model.pkl
├── Document_Regarding_All_The_Scenarios.docx
└── README.md

Each folder corresponds to a specific Docker setup — with its own app files, Dockerfiles, and commands to execute.


⚙️ SCENARIO 1 — Web App + DB in a Single Image

  • Combines a Flask web app and SQLite database into one container.
  • The model (model.pkl) predicts flower species using Iris dataset inputs.
  • Uses Waitress as the production WSGI server.
  • Database entries (predictions) are persisted within the same container.

Run:

docker build -t scenario_1:latest .
docker run -d -p 5000:5000 scenario_1:latest

⚙️ SCENARIO 2 — Separate Images for Web App and DB

  • Splits the web and database apps into two containers.
  • The web app communicates with the DB container using REST APIs.
  • Introduces Docker networking to enable inter-container communication.

Run:

# Build
docker build -t scenario_2:web -f webapp/Dockerfile .
docker build -t scenario_2:db -f dbapp/Dockerfile .

# Create network
docker network create my_iris

# Run containers
docker run -d -p 1234:1234 --name mywebapp --network my_iris scenario_2:web
docker run -d -p 4567:5678 --name db_container --network my_iris scenario_2:db

⚙️ SCENARIO 3 — Web + DB with Docker Compose

  • Uses a docker-compose.yml to bring up both services with one command.
  • Both containers share a user-defined bridge network.

Run:

docker compose -f mydockercomposefile.yaml up

⚙️ SCENARIO 4 — Adding Volumes for Persistence

  • Demonstrates data persistence using Docker volumes.
  • Even after deleting the DB container, data remains intact.

Run:

docker volume create sample_volume
docker run -d -p 1234:1234 --name mywebapp --network my_iris scenario_4:web
docker run -d -p 4567:5678 --name db_container --network my_iris -v sample_volume:/my_app scenario_4:db

⚙️ SCENARIO 5 — Docker Compose + Volumes

  • Extends Scenario 3 with persistent volumes using Compose.
  • Ensures data remains available across container restarts.

Run:

docker compose -f docker-compose.yaml up

⚙️ SCENARIO 6 — Import and Export Containers

  • Demonstrates exporting a container to a .tar file and importing it back.
  • Useful for sharing images offline.

Commands:

docker export <container_name> -o my_container.tar
docker import my_container.tar my_restored_image:latest
docker run -d -p 5000:5000 my_restored_image:latest

⚙️ SCENARIO 7 — Save and Load Images

  • Shows how to save a Docker image to a file and load it on another system.
  • Perfect for transferring builds between machines without rebuilding.

Commands:

# On local machine
docker save -o scenario_7.tar scenario_7:1

# On another machine
docker load -i scenario_7.tar
docker run -p 5000:5000 scenario_7:1

Endpoints: /, /predict, /show_entries


⚙️ SCENARIO 8 — Multi-Stage Build with Compose

  • Combines all learned concepts:

    • Multi-container setup
    • Persistent volumes
    • Multi-stage build optimization
    • Docker Compose orchestration

Run:

docker compose -f docker-compose.yaml up

🧠 Key Learnings

Throughout these 8 scenarios, I explored how Docker streamlines development and deployment workflows. Here’s what I learned along the way:

🏗️ Creating and managing Docker images & containers

🧩 Building multi-container applications using custom networks

💾 Persisting data with Docker volumes

⚙️ Automating builds and orchestration with Docker Compose

🚚 Sharing and migrating images using export/import and save/load

🪶 Optimizing builds through multi-stage Dockerfiles


🧩 Tech Stack

  • Docker / Docker Compose
  • Flask
  • SQLite
  • Python 3.13
  • Waitress WSGI Server
  • PyTorch (for model)

📘 How to Reproduce

Each scenario is fully reproducible:

  • Follow the step-by-step commands in the 📄 Practical Document.
  • Build or compose the containers as described.
  • Explore how each configuration behaves differently.

🧑‍💻 Author

Developed & Implemented by: Shrey Vyas

Scenario Design & Questions by: Dr. Priyank Thakkar

About

These are different Scenarios for working with Docker with their Commands

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages