From 786c7ea023a941b226b0caacfebc2b1d7b5a888e Mon Sep 17 00:00:00 2001 From: Satvik-Singh192 Date: Sat, 8 Nov 2025 12:42:31 +0530 Subject: [PATCH] feat: dockerized the firewall --- .dockerignore | 10 ++++++++++ Dockerfile | 17 ++++++++++++++++ README.md | 43 +++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 10 ++++++++++ entrypoint.sh | 16 +++++++++++++++ requirements_dev.txt | 5 +++++ requirements_docker.txt | 4 ++++ 7 files changed, 105 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 entrypoint.sh create mode 100644 requirements_dev.txt create mode 100644 requirements_docker.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ca2b53b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +venv/ +*.venv/ +__pycache__/ +*.pyc +*.pyo +*.pyd +.vscode/ +.idea/ + +.git/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5da8415 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.10-slim +WORKDIR /app +COPY requirements_docker.txt . + +RUN apt-get update && \ + apt-get install -y gcc build-essential python3-dev && \ + pip install -r requirements_docker.txt && \ + apt-get purge -y gcc build-essential python3-dev && \ + apt-get autoremove -y && \ + apt-get clean + + +COPY . . +RUN chmod +x /app/entrypoint.sh +ENTRYPOINT ["/app/entrypoint.sh"] + +CMD ["python", "main.py"] \ No newline at end of file diff --git a/README.md b/README.md index 1707088..520eb1d 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,49 @@ python3 main.py --create-config sudo python3 main.py -v ``` +# 🐳 Running with Docker + +Using Docker is the recommended way to run the firewall, as it automatically manages all dependencies and network permissions. + +--- + +## ✅ Prerequisites + +Make sure you have the following installed: + +- **Docker** +- **Docker Compose** + *(Docker Desktop for Windows/macOS includes both.)* + +--- + + +### **1. Build and Run** + +Open your terminal in the project’s root directory and run: + +```bash +docker-compose run --rm firewall +``` + +The image will build the **first time** you run this command. + +`--rm` ensures the container is automatically removed when it stops. + +--- + +## 2. Select Network Interface + +After the container starts, you will be prompted to choose the interface: + +Select an interface (0–2): 2 + + +--- + +## ✅ To Stop + +Press: Ctrl + C ## Configuration diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a389446 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + firewall: + build: . + container_name: firewall + + cap_add: + - NET_ADMIN + network_mode: "host" + + restart: unless-stopped \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..9b2153d --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# This script runs inside the container +# It checks if a config file exists. If not, it creates one. + +CONFIG_FILE="firewall_config.json" + +if [ ! -f "$CONFIG_FILE" ]; then + echo "--- No $CONFIG_FILE found, creating one... ---" + python main.py --create-config + echo "--- Default config file created. ---" +else + echo "--- Using existing $CONFIG_FILE. ---" +fi +echo "--- Starting firewall... ---" +exec "$@" \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..a7d4f9d --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,5 @@ +pytest>=7.0.0 +pytest-cov>=4.0.0 +black>=22.0.0 +flake8>=5.0.0 +isort>=5.10.0 \ No newline at end of file diff --git a/requirements_docker.txt b/requirements_docker.txt new file mode 100644 index 0000000..2536adc --- /dev/null +++ b/requirements_docker.txt @@ -0,0 +1,4 @@ +scapy>=2.4.0 +psutil>=5.8.0 +colorama>=0.4.0 +netifaces>=0.11.0 \ No newline at end of file