-
Notifications
You must be signed in to change notification settings - Fork 303
Docker #281
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?
Docker #281
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,34 @@ | ||
| ARG PYTHON_VERSION=3.11 | ||
|
|
||
| FROM python:${PYTHON_VERSION}-slim AS build | ||
|
|
||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| RUN python -m venv /opt/venv | ||
| ENV PATH="/opt/venv/bin:$PATH" | ||
|
|
||
| COPY requirements.txt . | ||
| RUN pip install --upgrade pip \ | ||
|
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 in the instructions references |
||
| && pip install --no-cache-dir -r requirements.txt | ||
|
|
||
| COPY . . | ||
| RUN python manage.py migrate | ||
|
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. You run |
||
|
|
||
| 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"] | ||
| 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 | ||
|
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. Consider linking directly to the image tag (1.0.0) or to the repository tags page so the grader/user can quickly verify the |
||
|
|
||
| ## Build the image | ||
|
|
||
| From the project root (`devops_todolist`): | ||
|
|
||
| ```powershell | ||
| docker build -t dimonalek/todoapp:1.0.0 . | ||
|
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 |
||
| ``` | ||
|
|
||
| ## 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 | ||
|
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. This example runs |
||
| ``` | ||
|
|
||
| ## 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" | ||
| ``` | ||
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.
INSTRUCTION.md contains a placeholder link with
<your-dockerhub-username>. The checklist requires a link to your personal Docker Hub repository hosting thetodoapp:1.0.0image — replace the placeholder with your actual Docker Hub URL (for example:https://hub.docker.com/r/yourusername/todoapp).