0% found this document useful (0 votes)
24 views7 pages

DevOps Case Study Final

This laboratory report details an experiment aimed at learning Dockerfile instructions to build a Docker image for a sample web application. It covers the introduction to Docker, its architecture, essential Dockerfile commands, advanced concepts, and practical exercises for containerizing a Flask web application. The report emphasizes the importance of Docker in modern software development for efficient deployment and scalability.

Uploaded by

paritosh8514
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views7 pages

DevOps Case Study Final

This laboratory report details an experiment aimed at learning Dockerfile instructions to build a Docker image for a sample web application. It covers the introduction to Docker, its architecture, essential Dockerfile commands, advanced concepts, and practical exercises for containerizing a Flask web application. The report emphasizes the importance of Docker in modern software development for efficient deployment and scalability.

Uploaded by

paritosh8514
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Laboratory Report

Case Study
Batch -

Date of Experiment: Date of Submission:

Title: To learn Dockerfile instructions, build a image for a sample web application
using Dockerfile.

Evaluation

1) Attendance [2] ----------------


2) Lab Performance [2] ----------------
3) Oral [1] ----------------

Overall Marks [5] ----------------

Subject Incharge
Aim- To learn Dockerfile instructions, build a image for a sample web
application using Dockerfile.

Theory:

1. Introduction to Docker
Docker is a powerful open-source platform that enables developers to build,
ship, and run applications in isolated environments known as containers.
Containerization has revolutionized software deployment by making
applications more portable, scalable, and efficient.

1.1 Evolution of Software Deployment


Before Docker, software deployment relied on traditional methods such as
Virtual Machines (VMs). However, VMs require separate guest operating
systems, making them resource-intensive. Containers solve this issue by
sharing the host OS, reducing overhead and improving performance.

1.2 Differences Between Virtual Machines and Containers


• VMs require a full OS for each instance, while containers share the host OS.

• Containers are lightweight compared to VMs, leading to faster startup times.

• VMs have significant memory and CPU overhead, whereas containers use
fewer resources.

• Containers provide better portability and scalability in cloud-native


applications.
2. Understanding Docker Architecture
Docker follows a client-server architecture, consisting of the following
components:

• Docker Client: The command-line interface (CLI) or API that interacts


with the Docker daemon.

• Docker Daemon: The background service responsible for building,


running, and managing containers.

• Docker Image: A lightweight, stand-alone package that contains


application code, dependencies, and configurations.

• Docker Container: A running instance of a Docker image that operates


in an isolated environment.

• Docker Registry: A repository where Docker images are stored and


shared, such as Docker Hub or private registries.

3. Detailed Explanation of Dockerfile Instructions

A Dockerfile is a script containing instructions to automate the creation of


Docker images. Below are detailed explanations of essential Dockerfile
commands:

• FROM: Specifies the base image to use for the container.

• WORKDIR: Sets the working directory inside the container.

• COPY: Copies files from the host system to the container.


• ADD: Similar to COPY but supports remote URLs and tar extraction.

• RUN: Executes commands inside the container during the image build
process.

• CMD: Specifies the default command to run when the container starts.

• ENTRYPOINT: Defines the main application process for the container.

• EXPOSE: Indicates the ports the container will listen on.

• ENV: Sets environment variables inside the container.

• ARG: Defines build-time variables that can be overridden.

• VOLUME: Creates a mount point for persistent storage.

• LABEL: Adds metadata to the image, such as version or maintainer


information.

4. Advanced Docker Concepts


As you become more familiar with Docker, it's important to understand
advanced concepts that enhance container performance, security, and
scalability.

• Multi-Stage Builds: Optimize image size by separating build dependencies


from runtime.

• Docker Networking: Configure bridge networks, host networks, and overlay


networks.

• Docker Compose: Manage multi-container applications using a YAML


configuration file.
• Docker Volumes: Persist data beyond the container lifecycle.

• Container Orchestration: Use Kubernetes or Docker Swarm to manage


containerized applications at scale.

5. Lab Exercise: Containerizing a Flask Web Application


In this exercise, we will create a simple Flask web application and containerize
it using Docker.

5.1 Step 1: Writing a Simple Flask Application


1. Create a project directory:

mkdir docker-flask-app && cd docker-flask-app

2. Create a Python application (app.py):

from flask import Flask

app = Flask(__name__)

@app.route('/') def
home():
return "Welcome to Dockerized Flask App!"

if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)

3. Create a requirements.txt file:

flask
5.2 Step 2: Writing an Optimized Dockerfile
Below is an optimized Dockerfile that follows best practices, such as
minimizing image size and security enhancements.

FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt requirements.txt

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 5000

CMD ["python", "app.py"]

5.3 Step 3: Building and Running the Docker Image


1. Build the Docker Image: docker build -t flask-app .

2. Run the Container:

docker run -p 5000:5000 flask-app

3. Access the Application:

Open a browser and visit: http://localhost:5000


6. Best Practices for Docker
Following best practices ensures efficient, secure, and scalable containerized
applications.

• Use minimal base images like Alpine to reduce vulnerabilities.

• Leverage multi-stage builds to keep images lightweight.

• Run containers as non-root users for improved security.

• Use Docker secrets instead of environment variables for sensitive data.

• Optimize caching by ordering Dockerfile instructions effectively.

• Regularly scan images for vulnerabilities using Docker security tools.

• Implement logging and monitoring using Prometheus and Grafana.

7. Conclusion
This lab manual provided an in-depth exploration of Docker, covering
fundamental concepts, advanced techniques, and practical exercises. By
containerizing a Flask web application, students gained hands-on experience
in writing Dockerfiles, building images, and running containers.
Understanding Docker is essential in modern software development, enabling
seamless deployment, scalability, and resource efficiency. Further exploration
of container orchestration, cloud deployment, and security best practices will
enhance proficiency in DevOps and cloud-native technologies.

You might also like