Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Build stage
ARG PYTHON_VERSION=3.12
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

Comment on lines +28 to +36

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The INSTRUCTION.md is missing the docker push command required by the task. Add: docker push nichelangoo/todoapp:1.0.0 (replace with your actual Docker Hub username) after the build instructions.

# 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"]
86 changes: 86 additions & 0 deletions INSTRUCTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 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 .
Comment on lines +32 to +33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build command tags the image as todoapp:1.0.0 but the requirement states the image should be named todoapp. Consider clarifying that the image name is todoapp with the tag 1.0.0 (e.g., docker build -t todoapp . for naming, then docker tag todoapp <username>/todoapp:1.0.0 before push).


# Or override the Python version explicitly
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 <username>/todoapp:1.0.0

# Push the image to Docker Hub
docker push <username>/todoapp:1.0.0
```

---

## Running the Container

```bash
docker run -d \
--name todoapp \
-p 8080:8080 \
Comment on lines +29 to +52

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instructions are missing the docker push command required by the task to push the image to Docker Hub with the 1.0.0 tag. Add: docker push nichelangelo/todoapp:1.0.0 (adjust username as needed).

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
```
Loading