From e1f66df416a03fe3249285cc55bc8e7358b769d7 Mon Sep 17 00:00:00 2001 From: ProstoPonchik Date: Tue, 26 May 2026 19:38:33 +0200 Subject: [PATCH 1/3] feat(docker): add Docker setup - add multi-stage Dockerfile - add .dockerignore - add INSTRUCTION.md with build and run instructions --- .dockerignore | 10 ++++++++++ Dockerfile | 26 ++++++++++++++++++++++++++ INSTRUCTION.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 INSTRUCTION.md diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2308bf1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.venv/ +.github/ +__pycache__/ +*.pyc +*.pyo +.travis.yml +.pre-commit-config.yaml +db.sqlite3 +README.md +.git/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ce30964 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +ARG PYTHON_VERSION=3.9 + +FROM python:${PYTHON_VERSION}-slim AS build + +ENV PYTHONUNBUFFERED=1 +WORKDIR /app + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +RUN python manage.py migrate + +FROM python:${PYTHON_VERSION}-slim AS run +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY --from=build /app /app +EXPOSE 8080 + +CMD [ "python", "manage.py", "runserver", "0.0.0.0:8080" ] \ No newline at end of file diff --git a/INSTRUCTION.md b/INSTRUCTION.md new file mode 100644 index 0000000..6d830cf --- /dev/null +++ b/INSTRUCTION.md @@ -0,0 +1,49 @@ +## Todo list application in Docker + +This is a to-do list web application with basic features of most web apps, i.e., accounts/login, API, and interactive UI. + +Link to the Docker Hub repository with the app image: [prostoponchik/todoapp](https://hub.docker.com/r/prostoponchik/todoapp) + +## Instructions for building and running the container from GitHub repository + +1. Clone the repository: + +``` +git clone https://github.com/ProstoPonchik/devops_todolist +``` + +2. Navigate to the project directory: + +``` +cd devops_todolist +``` + +3. Build the Docker image and name it `todoapp`: + +``` +docker build -t todoapp:1.0.0 . +``` + +4. Run the container: + +``` +docker run -d -p 8080:8080 --name todoapp_container todoapp:1.0.0 +``` + +## Instructions for running the container from Docker Hub image + +1. Pull the image from Docker Hub: + +``` +docker pull prostoponchik/todoapp:1.0.0 +``` + +2. Run the container: + +``` +docker run -d -p 8080:8080 --name todoapp_container prostoponchik/todoapp:1.0.0 +``` + +## Accessing the application via a browser + +Open your web browser and navigate to `http://localhost:8080/` to access the landing page of the ToDo application. You can also access the API at `http://localhost:8080/api/`. \ No newline at end of file From bcfc39764452bf92f91547f94e426c6f1863be15 Mon Sep 17 00:00:00 2001 From: ProstoPonchik Date: Tue, 26 May 2026 20:00:41 +0200 Subject: [PATCH 2/3] fix(docker): update Dockerfile and instructions --- Dockerfile | 8 ++++---- INSTRUCTION.md | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index ce30964..7c028f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,9 @@ ENV PYTHONUNBUFFERED=1 WORKDIR /app COPY requirements.txt ./ -RUN pip install --no-cache-dir -r requirements.txt + +RUN pip install --no-cache-dir --prefix=/install -r requirements.txt +RUN cp -a /install/. /usr/local/ COPY . . @@ -17,9 +19,7 @@ ENV PYTHONUNBUFFERED=1 WORKDIR /app -COPY requirements.txt ./ -RUN pip install --no-cache-dir -r requirements.txt - +COPY --from=build /install /usr/local COPY --from=build /app /app EXPOSE 8080 diff --git a/INSTRUCTION.md b/INSTRUCTION.md index 6d830cf..2614b4e 100644 --- a/INSTRUCTION.md +++ b/INSTRUCTION.md @@ -30,6 +30,27 @@ docker build -t todoapp:1.0.0 . docker run -d -p 8080:8080 --name todoapp_container todoapp:1.0.0 ``` +## Publishing the image to Docker Hub + +1. Log in to your Docker Hub account: + +``` +docker login +``` + +2. Tag the image for your Docker Hub repository: + +``` +docker tag todoapp:1.0.0 prostoponchik/todoapp:1.0.0 +``` + +3. Push the image to Docker Hub: + +``` +docker push prostoponchik/todoapp:1.0.0 +``` + + ## Instructions for running the container from Docker Hub image 1. Pull the image from Docker Hub: From 92a8341e4231ad14ee7f6aa65e8154fd96792318 Mon Sep 17 00:00:00 2001 From: ProstoPonchik Date: Thu, 28 May 2026 08:58:04 +0200 Subject: [PATCH 3/3] feat(docker): change instruction docker hub push and fix Dockerfile --- Dockerfile | 4 ++-- INSTRUCTION.md | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7c028f5..0693fb1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,8 @@ ENV PYTHONUNBUFFERED=1 WORKDIR /app -COPY --from=build /install /usr/local +COPY --from=build /usr/local /usr/local COPY --from=build /app /app EXPOSE 8080 -CMD [ "python", "manage.py", "runserver", "0.0.0.0:8080" ] \ No newline at end of file +CMD [ "python", "manage.py", "runserver", "0.0.0.0:8080" ] diff --git a/INSTRUCTION.md b/INSTRUCTION.md index 2614b4e..39d227f 100644 --- a/INSTRUCTION.md +++ b/INSTRUCTION.md @@ -18,16 +18,16 @@ git clone https://github.com/ProstoPonchik/devops_todolist cd devops_todolist ``` -3. Build the Docker image and name it `todoapp`: +3. Build the Docker image and tag it for Docker Hub: ``` -docker build -t todoapp:1.0.0 . +docker build -t todoapp:1.0.0 -t prostoponchik/todoapp:1.0.0 . ``` 4. Run the container: ``` -docker run -d -p 8080:8080 --name todoapp_container todoapp:1.0.0 +docker run -d -p 8080:8080 --name todoapp_container prostoponchik/todoapp:1.0.0 ``` ## Publishing the image to Docker Hub @@ -67,4 +67,4 @@ docker run -d -p 8080:8080 --name todoapp_container prostoponchik/todoapp:1.0.0 ## Accessing the application via a browser -Open your web browser and navigate to `http://localhost:8080/` to access the landing page of the ToDo application. You can also access the API at `http://localhost:8080/api/`. \ No newline at end of file +Open your web browser and navigate to `http://localhost:8080/` to access the landing page of the ToDo application. You can also access the API at `http://localhost:8080/api/`.