0% found this document useful (0 votes)
15 views3 pages

Docker Project 11-03-2025

This document provides a step-by-step guide for creating a Docker-based project, including prerequisites, creating a project directory, adding application code, and defining a Dockerfile. It also covers building and running the Docker image, using Docker Compose for multi-container applications, and optionally pushing the image to Docker Hub. The example focuses on a simple Python Flask application setup.

Uploaded by

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

Docker Project 11-03-2025

This document provides a step-by-step guide for creating a Docker-based project, including prerequisites, creating a project directory, adding application code, and defining a Dockerfile. It also covers building and running the Docker image, using Docker Compose for multi-container applications, and optionally pushing the image to Docker Hub. The example focuses on a simple Python Flask application setup.

Uploaded by

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

Creating a Docker-based project involves defining and deploying applications in containers.

Here's a step-by-step guide to creating a Docker project:

1. Prerequisites
 Install Docker.
 Verify installation:

bash
Copy code
docker --version

2. Create Your Project Directory


Create a directory for your project:

bash
Copy code
mkdir my-docker-project && cd my-docker-project

3. Add Application Code


For example, if you're creating a simple Python Flask app:

1. Create app.py:

python
Copy code
from flask import Flask
app = Flask(__name__)

@app.route("/")
def home():
return "Hello, Docker!"

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

2. Add requirements.txt for dependencies:

Copy code
flask
4. Create a Dockerfile
The Dockerfile defines how to build your application image:

dockerfile
Copy code
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set the working directory in the container


WORKDIR /app

# Copy the current directory contents into the container


COPY . /app

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Expose the application's port


EXPOSE 5000

# Run the application


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

5. Build the Docker Image


Run the following command to build your image:

bash
Copy code
docker build -t my-docker-app .

6. Run the Docker Container


Start the container from your image:

bash
Copy code
docker run -p 5000:5000 my-docker-app

Visit http://localhost:5000 to see your app running!

7. Add a docker-compose.yml (Optional)


To manage multi-container apps or simplify commands, use Docker Compose. Example:
yaml
Copy code
version: "3.8"
services:
app:
build: .
ports:
- "5000:5000"

Run with:

bash
Copy code
docker-compose up

8. Push to Docker Hub (Optional)


Tag and push your image to Docker Hub:

bash
Copy code
docker tag my-docker-app <your-dockerhub-username>/my-docker-app
docker push <your-dockerhub-username>/my-docker-app

You might also like