From 91dffd6682dfecfc9525d15ca85faccb8acdcd7e Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 8 May 2026 01:06:44 +0200 Subject: [PATCH 1/5] Add DockerFile --- Dockerfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e69de29 From e4867c1f5ec42580710871f845e098b75eca4782 Mon Sep 17 00:00:00 2001 From: Oleksandr Tkachuk Date: Fri, 8 May 2026 15:54:15 +0200 Subject: [PATCH 2/5] Add initial Dockerfile for Python Flask application --- Dockerfile | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Dockerfile b/Dockerfile index e69de29..ef54485 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,18 @@ +# Use the official Python image as the base image +FROM python:3.8 + +# Set the working directory within the container +WORKDIR /app + +# Copy the application code into the container +COPY app.py . +COPY docker-logo.png . + +# Install Flask and other dependencies +RUN pip install Flask + +# Expose port 8080 to the host +EXPOSE 8080 + +# Define the command to run the application +ENTRYPOINT ["python", "app.py"] From 7dc1f4902d4001dd9a26e8b803f6ce90f1576b02 Mon Sep 17 00:00:00 2001 From: Oleksandr Tkachuk Date: Sun, 17 May 2026 11:52:12 +0200 Subject: [PATCH 3/5] Add Dockerfile and INSTRUCTION.md for container setup and usage --- .dockerignore | 12 +++++++ Dockerfile | 57 ++++++++++++++++++++++++------ INSTRUCTION.md | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 INSTRUCTION.md diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e0abdf1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +.github +.venv +__pycache__ +.git +.gitignore +Dockerfile +docker-compose.yml +INSTRUCTION.md +README.md +.dockerignore +.pre-commit-config.yaml +.travis.yml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ef54485..7ed5b0d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,53 @@ -# Use the official Python image as the base image -FROM python:3.8 +### Builder stage +ARG PYTHON_VERSION=3.8 + +FROM python:${PYTHON_VERSION}-slim AS builder -# Set the working directory within the container WORKDIR /app -# Copy the application code into the container -COPY app.py . -COPY docker-logo.png . +COPY requirements.txt . + +# Install system build dependencies and Python build +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + build-essential \ + gcc \ + python3-dev \ + libbz2-dev \ + libssl-dev \ + libffi-dev \ + && rm -rf /var/lib/apt/lists/* \ + && pip install --upgrade pip wheel \ + && pip install --no-cache-dir \ + --prefix=/install \ + -r requirements.txt + +### Runtime stage +FROM python:${PYTHON_VERSION}-slim + +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app + +# Create non-root user +RUN useradd --create-home --uid 1001 appuser + +# Copy installed packages +COPY --from=builder /install /usr/local + +# Copy application source +COPY . . + +# Set ownership +RUN chown -R appuser:appuser /app + +# Switch to non-root user +USER appuser -# Install Flask and other dependencies -RUN pip install Flask +RUN python manage.py migrate -# Expose port 8080 to the host +# Application port EXPOSE 8080 -# Define the command to run the application -ENTRYPOINT ["python", "app.py"] +# Start app +CMD ["python", "manage.py", "runserver", "0.0.0.0:8080"] \ No newline at end of file diff --git a/INSTRUCTION.md b/INSTRUCTION.md new file mode 100644 index 0000000..a167947 --- /dev/null +++ b/INSTRUCTION.md @@ -0,0 +1,96 @@ +Docker Hub image +--------------- + +This repository has a prebuilt Docker image available on Docker Hub: + +https://hub.docker.com/r/verteiger/todoapp + +Quick start — pull and run +-------------------------- + +1. Pull the image from Docker Hub: + + docker pull verteiger/todoapp:latest + +2. Run the container, mapping the container port 8080 to a host port (example uses host port 8000): + + docker run --rm -p 8000:8080 verteiger/todoapp:latest + + - `--rm` removes the container after exit. Omit if you want to keep the container. + +Build the image locally +----------------------- + +If you prefer to build the image from source locally: + +1. Build the image (run from the repository root): + + docker build -t verteiger/todoapp:latest . + +2. Run the locally-built image: + + docker run --rm -p 8000:8080 verteiger/todoapp:latest + +Push to Docker Hub +------------------ + +To publish your local build to Docker Hub (you must own the `verteiger/todoapp` repo or change the tag to your own): + +1. Log in to Docker Hub: + + docker login + +2. Tag the image (if needed): + + docker tag verteiger/todoapp:latest verteiger/todoapp:latest + +3. Push: + + docker push verteiger/todoapp:latest + +Notes about the container +------------------------- + +- The container runs the Django development server on port `8080` inside the container (see `Dockerfile`). +- We recommend mapping it to a non-conflicting host port, e.g. `8000` as shown above. +- The container runs migrations at start (`python manage.py migrate`) so the first run may take longer. + +Access the application in a browser +---------------------------------- + +After running the container with `-p 8000:8080`, open your browser and go to: + +http://localhost:8000/ + +If you mapped to a different host port, replace `8000` with that port. + +Optional: Docker Compose +------------------------ + +Create a `docker-compose.yml` file with a service like: + +```yaml +version: '3.8' +services: + todoapp: + image: verteiger/todoapp:latest + ports: + - "8000:8080" + restart: unless-stopped +``` + +Then run: + +```bash +docker-compose up -d +``` + +Troubleshooting +--------------- + +- If the site is unreachable, check Docker logs: + + docker logs + +- Ensure no other service is already listening on the chosen host port. + From 505a1d2ec1f15c131383cfff138ad3f5e19a7968 Mon Sep 17 00:00:00 2001 From: Oleksandr Tkachuk Date: Sun, 17 May 2026 12:06:24 +0200 Subject: [PATCH 4/5] fix tag name --- INSTRUCTION.md | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/INSTRUCTION.md b/INSTRUCTION.md index a167947..b790f86 100644 --- a/INSTRUCTION.md +++ b/INSTRUCTION.md @@ -10,13 +10,11 @@ Quick start — pull and run 1. Pull the image from Docker Hub: - docker pull verteiger/todoapp:latest + docker pull verteiger/todoapp:1.0.0 2. Run the container, mapping the container port 8080 to a host port (example uses host port 8000): - docker run --rm -p 8000:8080 verteiger/todoapp:latest - - - `--rm` removes the container after exit. Omit if you want to keep the container. + docker run --rm -p 8000:8080 todoapp:1.0.0 Build the image locally ----------------------- @@ -25,13 +23,11 @@ If you prefer to build the image from source locally: 1. Build the image (run from the repository root): - docker build -t verteiger/todoapp:latest . + docker build -t todoapp:1.0.0 . 2. Run the locally-built image: - docker run --rm -p 8000:8080 verteiger/todoapp:latest - -Push to Docker Hub + docker run --rm -p 8000:8080 todoapp:1.0.0 ------------------ To publish your local build to Docker Hub (you must own the `verteiger/todoapp` repo or change the tag to your own): @@ -42,11 +38,11 @@ To publish your local build to Docker Hub (you must own the `verteiger/todoapp` 2. Tag the image (if needed): - docker tag verteiger/todoapp:latest verteiger/todoapp:latest + docker tag todoapp:1.0.0 verteiger/todoapp:1.0.0 3. Push: - docker push verteiger/todoapp:latest + docker push verteiger/todoapp:1.0.0 Notes about the container ------------------------- @@ -73,11 +69,7 @@ Create a `docker-compose.yml` file with a service like: version: '3.8' services: todoapp: - image: verteiger/todoapp:latest - ports: - - "8000:8080" - restart: unless-stopped -``` + image: todoapp:1.0.0 Then run: From 56344c0142c00c70c588e22605acd7615235a650 Mon Sep 17 00:00:00 2001 From: Oleksandr Tkachuk Date: Sun, 17 May 2026 19:49:31 +0200 Subject: [PATCH 5/5] Fixed requested changes. --- INSTRUCTION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTRUCTION.md b/INSTRUCTION.md index b790f86..00e938a 100644 --- a/INSTRUCTION.md +++ b/INSTRUCTION.md @@ -77,6 +77,7 @@ Then run: docker-compose up -d ``` + Troubleshooting --------------- @@ -85,4 +86,3 @@ Troubleshooting docker logs - Ensure no other service is already listening on the chosen host port. -