From 5e046a828cc8e4600231838de1c4299e8ce56505 Mon Sep 17 00:00:00 2001 From: Nikita Ivanichenko Date: Sun, 31 May 2026 00:34:52 +0300 Subject: [PATCH 1/2] Solution --- Dockerfile | 41 ++++++++++++++++++++++++++ INSTRUCTION.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 Dockerfile create mode 100644 INSTRUCTION.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0859155 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +# Build stage +ARG PYTHON_VERSION=3.14 +FROM python:${PYTHON_VERSION} AS base + +WORKDIR /app + +# Copy list of required packages to install +COPY requirements.txt ./ + +# Create venv +RUN python -m venv venv + +# Install requirements using venv and upgrade pip +RUN ./venv/bin/pip install --upgrade pip && \ + ./venv/bin/pip install -r requirements.txt + +# Copy the application code into the container +COPY accounts ./accounts/ +COPY api ./api/ +COPY lists ./lists/ +COPY todolist ./todolist/ +COPY manage.py ./ + +# Runtime stage +FROM python:${PYTHON_VERSION}-slim +WORKDIR /app + +# Set an environment variable for the runtime +ENV PYTHONUNBUFFERED=1 + +# Copy the built application and installed dependencies from the build stage +COPY --from=base /app . + +# Run migration +RUN ./venv/bin/python manage.py migrate + +# Expose port 8080 to the host +EXPOSE 8080 + +# Define the command to run the application +CMD ["./venv/bin/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..d66e556 --- /dev/null +++ b/INSTRUCTION.md @@ -0,0 +1,80 @@ +# TodoApp — Docker Instructions + +## Docker Hub Repository + +The application image is available at: + +``` +https://hub.docker.com/repository/docker/nichelangeloo/todoapp/general +``` + +--- + +## Dockerfile Overview + +The `Dockerfile` uses a **two-stage build**: + +- **Build stage** — installs Python dependencies into an isolated layer. +- **Run stage** — copies only the installed packages and application code into a clean final image, keeping the image small. + +Key configuration: + +- `ARG PYTHON_VERSION` — parameterises the Python base image version (e.g. `3.14-slim`). +- `ENV PYTHONUNBUFFERED=1` — logs are written directly to stdout/stderr without buffering. +- Database migrations are applied at build time via a `RUN python manage.py migrate` instruction. +- The server is started with `python manage.py runserver 0.0.0.0:8080` so it is reachable from outside the container. + +--- + +## Building the Image Locally + +```bash +# Build with the default Python version +docker build -t todoapp:1.0.0 . + +# Or override the Python version explicitly +docker build --build-arg PYTHON_VERSION=3.12-slim -t todoapp:1.0.0 . +``` + +--- + +## Running the Container + +```bash +docker run -d \ + --name todoapp \ + -p 8080:8080 \ + todoapp:1.0.0 +``` + +| Flag | Purpose | +| ---------------- | --------------------------------------------- | +| `-d` | Run in detached (background) mode | +| `--name todoapp` | Assign a human-readable name to the container | +| `-p 8080:8080` | Map host port 8080 to the container port 8080 | + +--- + +## Accessing the Application + +Once the container is running, open your browser and navigate to: + +``` +http://localhost:8080 +``` + +To verify the container is up: + +```bash +docker ps +docker logs todoapp +``` + +--- + +## Stopping and Removing the Container + +```bash +docker stop todoapp +docker rm todoapp +``` From e205c315edbc5215b04db4c6524f85f64abd8a1e Mon Sep 17 00:00:00 2001 From: Nikita Ivanichenko Date: Sun, 31 May 2026 00:48:24 +0300 Subject: [PATCH 2/2] fix --- Dockerfile | 2 +- INSTRUCTION.md | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0859155..1990805 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build stage -ARG PYTHON_VERSION=3.14 +ARG PYTHON_VERSION=3.12 FROM python:${PYTHON_VERSION} AS base WORKDIR /app diff --git a/INSTRUCTION.md b/INSTRUCTION.md index d66e556..86dc64f 100644 --- a/INSTRUCTION.md +++ b/INSTRUCTION.md @@ -33,7 +33,13 @@ Key configuration: docker build -t todoapp:1.0.0 . # Or override the Python version explicitly -docker build --build-arg PYTHON_VERSION=3.12-slim -t todoapp:1.0.0 . +docker build --build-arg PYTHON_VERSION=3.11-slim -t todoapp:1.0.0 . + +# Tag the image for Docker Hub +docker tag todoapp:1.0.0 /todoapp:1.0.0 + +# Push the image to Docker Hub +docker push /todoapp:1.0.0 ``` ---