-
Notifications
You must be signed in to change notification settings - Fork 331
Solution #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Solution #304
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| # 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"] | ||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The build command tags the image as |
||
|
|
||
| # 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The instructions are missing the |
||
| 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 | ||
| ``` | ||
There was a problem hiding this comment.
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 pushcommand required by the task. Add:docker push nichelangoo/todoapp:1.0.0(replace with your actual Docker Hub username) after the build instructions.