Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.github
.venv
__pycache__
.git
.gitignore
Dockerfile
docker-compose.yml
INSTRUCTION.md
README.md
.dockerignore
.pre-commit-config.yaml
.travis.yml
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### Builder stage
ARG PYTHON_VERSION=3.8

FROM python:${PYTHON_VERSION}-slim AS builder

WORKDIR /app
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 Docker Hub link shows verteiger/todoapp which appears to be a personal repository, but the image should be named todoapp with tag 1.0.0 as per requirements. Verify this matches your actual Docker Hub repository or update accordingly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed


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 \
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 image tag mentioned is latest but task requirement #9 requires the image to be pushed with 1.0.0 tag (todoapp:1.0.0). Update all references from latest to 1.0.0.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

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

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 image is built with tag verteiger/todoapp:latest but task requirement #8 specifies it should be named todoapp. Change -t verteiger/todoapp:latest to -t todoapp:1.0.0 to match the requirement.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

ENV PYTHONUNBUFFERED=1

WORKDIR /app

# Create non-root user
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Image tag should be 1.0.0 instead of latest to match task requirement #9.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Image tag should be 1.0.0 instead of latest to match task requirement #9.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed


RUN python manage.py migrate

# Application port
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Image tag should be 1.0.0 instead of latest to match task requirement #9.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

EXPOSE 8080

# Start app
CMD ["python", "manage.py", "runserver", "0.0.0.0:8080"]
96 changes: 96 additions & 0 deletions INSTRUCTION.md
Original file line number Diff line number Diff line change
@@ -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):

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 pull command uses todoapp:latest but should reference todoapp:1.0.0 to match the task requirement for the specific tag.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

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):

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 task requirement #9 specifies the image should be pushed with the 1.0.0 tag (todoapp:1.0.0), but the build command uses todoapp:latest. Update to use todoapp:1.0.0 for consistency with the requirement.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

docker build -t verteiger/todoapp:latest .

2. Run the locally-built image:

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 run command uses todoapp:latest but should use todoapp:1.0.0 to match the specified tag in the task requirements.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

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):

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 tag command uses todoapp:latest but should be todoapp:1.0.0 as specified in the task requirement.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

docker tag verteiger/todoapp:latest verteiger/todoapp:latest

3. Push:

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 push command uses todoapp:latest but should push todoapp:1.0.0 to match the task requirement.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

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:
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 docker-compose service uses todoapp:latest image tag but should use todoapp:1.0.0 for consistency with the task requirement.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

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 <container-id>

- Ensure no other service is already listening on the chosen host port.

Loading