diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..794de1b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +__pycache__/ +*.pyc +*.pyo +*.pyd +*.db +*.sqlite3 +.env +.git +.gitignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1a6d76d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use official lightweight Python image +FROM python:3.10-slim + +# Set working directory +WORKDIR /app + +# Copy requirements first (for caching) +COPY requirements.txt . + +# Install dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy all project files +COPY . . + +# Expose Flask default port +EXPOSE 5000 + +# Run the Flask app +CMD ["python", "app.py"] diff --git a/README.md b/README.md index aac6ae5..91cdb7a 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,55 @@ For more basic knowledge of Flask, you can refer to [a tutorial on Tutorialspoin - Step 3: Go to this app's directory and run `python app.py` +## How to Run (Docker way) +This app has been containerized using Docker. You can run it easily on any machine without worrying about dependencies. +## Prerequisites for Docker + +Before running the app using Docker, make sure you have the following installed: + +1. **Git** – to clone or fork the repository + - [Download Git](https://git-scm.com/downloads) + +2. **Docker** – to build and run containers + - [Download Docker](https://www.docker.com/get-started) + +3. **Docker Compose** – to run multi-container apps (usually comes with Docker Desktop) + - [Install Docker Compose](https://docs.docker.com/compose/install/) + +### Steps to Run the App + +1. **Clone or fork the repository:** +```bash +git clone https://github.com/your-username/your-repo.git + +cd your-repo +``` + +2. **Build and start containers:** +```bash +docker-compose up -d +``` +3. **Check running containers:** +```bash +docker ps +``` +4. **Open the app in your browser:** +[runs on localhost:5000](http://localhost:5000) + +5. **Stop containers:** +```bash +docker-compose down +``` + +## Benefits: + +-Easy setup: No need to install Python or dependencies manually. + +-Consistency: Same behavior across all environments (dev, staging, production). + +-Portability: Can run anywhere Docker is available. + +-Isolation: Dependencies are separated from the host machine. ## Details about This Toy App diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..cb36247 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ + +services: + web: + build: . + container_name: flask-example + ports: + - "5000:5000" + volumes: + - .:/app + environment: + - FLASK_ENV=development diff --git a/requirements.txt b/requirements.txt index af34996..189d3f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ -Flask==1.1.2 -Werkzeug==1.0.1 -markupsafe==2.0.1 +Flask==2.2.5 +Werkzeug==2.2.3 +markupsafe==2.1.1 +Jinja2==3.1.2