From 98bcf1a5f06b99fde50135da9475e4a00a53709c Mon Sep 17 00:00:00 2001 From: Simardeep Singh <1003simar@gmail.com> Date: Fri, 13 Oct 2023 19:30:46 -0600 Subject: [PATCH] feat: Add advanced Dockerfile and Docker Compose files #656 --- .dockerignore | 6 ++++++ .gitignore | 11 ++++++++++- Dockerfile | 27 +++++++++++++++++++++++++++ docker-compose.dev.yml | 11 +++++++++++ docker-compose.prod.yml | 7 +++++++ 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.dev.yml create mode 100644 docker-compose.prod.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..afe2c555 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +__pycache__ +*.pyc +*.pyo +*.pyd +db.sqlite3 +.env diff --git a/.gitignore b/.gitignore index 496ee2ca..ac9776e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,10 @@ -.DS_Store \ No newline at end of file +.DS_Store +__pycache__ +*.pyc +*.pyo +*.pyd +*.db +*.log +*.env +*.pyz +*.pyw diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..530e39fd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +# Use an official Python image as a parent image +FROM python:3.8-slim + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# Set the working directory inside the container +WORKDIR /app + +# Copy only the requirements file into the container +COPY requirements.txt . + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of your application code into the container +COPY . . + +# Collect static files if applicable (for Django, Flask, etc.) +# RUN python manage.py collectstatic --noinput + +# Expose the necessary port (if your app listens on a specific port) +EXPOSE 8000 + +# Define the command to run your application +CMD [ "python", "app.py" ] diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 00000000..34c2fff9 --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,11 @@ +version: '3' +services: + app: + build: + context: . + dockerfile: Dockerfile + command: ["python", "app.py"] + volumes: + - .:/app + ports: + - "8000:8000" diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 00000000..a24c532a --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,7 @@ +version: '3' +services: + app: + build: + context: . + dockerfile: Dockerfile + command: ["gunicorn", "-w", "4", "-b", "0.0.0.0:8000", "app:app"]