DEV Community

Cover image for Docker for Beginners: How I Containerized an Existing Project Node-by-Node

Docker for Beginners: How I Containerized an Existing Project Node-by-Node

INTRODUCTION

The Local Government Report System is a system develop for people in a Local Government to report any activity going in their area in order for the local government representative.
I dockerized this project in order to make because dockerization is important for project to provides conistent and reliale way to deploy applications across different environments.

PROJECT OVERVIEW

The Project was cloned from GitHub and the READ.ME was read in order to understand what the projects entails which I learnt that it run in a Virtual environment venv. And with docker we dont need to set up virtual environment.

WORKFLOW OF THE EXISTING PROJECT

  • venv

  • SQLAchemy

  • Template/Admin_dashoard.html, base.html, index.html, login.html, manage_user.html, new_complaint.html e.t.c

CLONING OF THE GITHUB REPO

This is the image representation of the clone project

CREATING A DOCKERFILE FOR THE APPLICATION

FROM python:3.11-slim

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 500

CMD ["python", "app.py"]

Enter fullscreen mode Exit fullscreen mode

BUILDING DOCKER IMAGE

After the Dockerfile is store with the clone system file that I proceed to create the Image using sudo docker build -t citizen-report

RUNNING THE DOCKER CONTAINER

During the running I perform port mapping 8080 with 5000 8080:5000 this allow the application to run in localhost:8080.
The command used for this is sudo docker run -d -p 8080:5000 --name local-report-container citizen-report
The command means that I have an image named citizen-report and run it a container named local-report-container, making the listen port 8080 and the application is available at 5000.

OUTPUT OF THE WORK

The application is running in http//localhost:8080

Common Error Fixed in the project

  1. Syntax error in the Dockerfile some --, " and others
  2. Wrong Port, Missing requirement.txt et.c

TO Detect were the error are comming from run sudo docker log <image-name>

THANKS FOR YOUR TIME

STAY TUNED FOR MORE ARTICLE ON DOCKER UP NEXT Docker Compose, CI/CD

Top comments (0)