-
Notifications
You must be signed in to change notification settings - Fork 311
Add Dockerfile with multi-stage build and INSTRUCTION.md #296
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?
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 @@ | ||
| # ─── Build Stage ─────────────────────────────────────────────────────────────── | ||
| ARG PYTHON_VERSION=3.11 | ||
|
|
||
| FROM python:${PYTHON_VERSION}-slim AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Install dependencies into a separate location for clean copying | ||
| COPY requirements.txt . | ||
| RUN pip install --upgrade pip && \ | ||
| pip install --no-cache-dir --prefix=/install -r requirements.txt | ||
|
|
||
|
|
||
| # ─── Run Stage ───────────────────────────────────────────────────────────────── | ||
| ARG PYTHON_VERSION=3.11 | ||
|
|
||
| FROM python:${PYTHON_VERSION}-slim | ||
|
|
||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy installed packages from builder | ||
| COPY --from=builder /install /usr/local | ||
|
|
||
| # Copy project source code | ||
| COPY . . | ||
|
|
||
| # Run database migrations | ||
| RUN python manage.py migrate | ||
|
|
||
| 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,78 @@ | ||
| # ToDo App — Docker Instructions | ||
|
|
||
| ## Docker Hub Repository | ||
|
|
||
| Image is available at: | ||
| **https://hub.docker.com/r/vadymmoldovan/todoapp** | ||
|
|
||
| --- | ||
|
|
||
| ## 1. Build the Docker Image | ||
|
|
||
| Clone the repository and build the image: | ||
|
|
||
| ```bash | ||
| git clone https://github.com/VadymMoldovan/devops_todolist.git | ||
| cd devops_todolist | ||
|
|
||
| docker build -t todoapp:1.0.0 . | ||
| ``` | ||
|
|
||
| To build with a custom Python version (optional): | ||
|
|
||
| ```bash | ||
| docker build --build-arg PYTHON_VERSION=3.11 -t todoapp:1.0.0 . | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 2. Run the Container | ||
|
|
||
| ```bash | ||
| docker run -d -p 8080:8080 --name todoapp todoapp:1.0.0 | ||
| ``` | ||
|
|
||
| | Flag | Description | | ||
| |------|-------------| | ||
| | `-d` | Run in detached (background) mode | | ||
| | `-p 8080:8080` | Map port 8080 of the container to port 8080 on your machine | | ||
| | `--name todoapp` | Name the running container | | ||
|
|
||
| --- | ||
|
|
||
| ## 3. Access the Application in a Browser | ||
|
|
||
| Open your browser and navigate to: | ||
|
|
||
| ``` | ||
| http://localhost:8080 | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 4. Pull the Image from Docker Hub (alternative) | ||
|
|
||
| Instead of building locally, you can pull the pre-built image: | ||
|
|
||
| ```bash | ||
|
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 pull command uses placeholder 'YOUR_DOCKERHUB_USERNAME' - should contain actual Docker Hub username for the repository. |
||
| docker pull vadymmoldovan/todoapp:1.0.0 | ||
| docker run -d -p 8080:8080 --name todoapp vadymmoldovan/todoapp:1.0.0 | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 5. Push Image to Docker Hub (for maintainers) | ||
|
|
||
| ```bash | ||
|
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 tag command uses placeholder 'YOUR_DOCKERHUB_USERNAME' - should contain actual Docker Hub username. |
||
| docker tag todoapp:1.0.0 vadymmoldovan/todoapp:1.0.0 | ||
| docker push vadymmoldovan/todoapp:1.0.0 | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 6. Stop and Remove 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.
This should be your actual Docker Hub username (e.g., VadymMoldovan) not a placeholder. The requirement states the link should point to your personal Docker Hub repository.