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
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ARG PYTHON_VERSION=3.11

FROM python:${PYTHON_VERSION}-slim AS build

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

INSTRUCTION.md contains a placeholder link with <your-dockerhub-username>. The checklist requires a link to your personal Docker Hub repository hosting the todoapp:1.0.0 image — replace the placeholder with your actual Docker Hub URL (for example: https://hub.docker.com/r/yourusername/todoapp).

WORKDIR /app

RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

COPY requirements.txt .
RUN pip install --upgrade pip \
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 in the instructions references -f DockerFile. The task description explicitly asks for a file named Dockerfile. Either rename the file to Dockerfile (preferred) or clearly state in INSTRUCTION.md that the Dockerfile is named DockerFile and ensure all commands use -f DockerFile. Renaming to Dockerfile avoids confusion and matches the checklist.

&& pip install --no-cache-dir -r requirements.txt

COPY . .
RUN python manage.py migrate
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You run python manage.py migrate during the image build (RUN python manage.py migrate). This satisfies the checklist item to execute migrations as a RUN instruction, but it may fail if your app uses a remote DB (the DB is often unavailable during image build). Consider documenting this caveat in INSTRUCTION.md or, if using an external DB, run migrations at container startup instead.


FROM python:${PYTHON_VERSION}-slim AS run

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

COPY --from=build /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

COPY --from=build /app /app

EXPOSE 8080

CMD ["python", "manage.py", "runserver", "0.0.0.0:8080"]
57 changes: 57 additions & 0 deletions INSTRUCTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Todo App Docker Instructions

## Docker Hub Repository

https://hub.docker.com/r/dimonalek/todoapp
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider linking directly to the image tag (1.0.0) or to the repository tags page so the grader/user can quickly verify the 1.0.0 image exists. Right now this points to the repo root which is fine, but a tag-specific link is clearer for validation.


## Build the image

From the project root (`devops_todolist`):

```powershell
docker build -t dimonalek/todoapp:1.0.0 .
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 dimonalek/todoapp:1.0.0. The task also mentions building an image named todoapp — if the grader expects an image named todoapp add an additional build/tag command (for example docker build -t todoapp:1.0.0 . or docker tag dimonalek/todoapp:1.0.0 todoapp:1.0.0).

```

## Tag and push image to Docker Hub

1. Log in to Docker Hub:

```powershell
docker login
```

2. Push the image:

```powershell
docker push dimonalek/todoapp:1.0.0
```

## Run the container

```powershell
docker run --rm -p 8080:8080 dimonalek/todoapp:1.0.0
```

If you want to run your local image (without pull), use:

```powershell
docker run --rm -p 8080:8080 todoapp
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This example runs todoapp (unqualified). That will fail unless you have a local image named todoapp. Consider replacing this with dimonalek/todoapp:1.0.0 or show a docker tag command to create the todoapp alias locally so users can run the unqualified name.

```

## Access in browser

After the container starts, open:

http://localhost:8080/

API endpoint:

http://localhost:8080/api/

## Note on database migrations

The `Dockerfile` runs `python manage.py migrate` during the image build stage using the bundled SQLite database. If you switch to a remote database (e.g., PostgreSQL), the build-time migration will fail because the database is not reachable at build time. In that case, remove the `RUN python manage.py migrate` line from the `Dockerfile` and run migrations at container startup instead — for example by overriding the container command:

```powershell
docker run --rm -p 8080:8080 dimonalek/todoapp:1.0.0 sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8080"
```
Loading