Dockerize a Project

What is Docker?

Quick Introduction

Tree structure of the project

Using Docker

  • It uses python base image with the tag 3.10 which is a specific version of Python.
  • It ensures that the python output is sent straight to the terminal (e.g the container log) without being first buffered so you can see the output of the application in real time.
  • It created a directory called app in the / (root)and then it install a Python package called pipenv.
  • Then it change the working directory from there on to /app which is then followed by copying the edom_backend directory contents to the /app .
  • It look for the requirements of the app from Pipfile located in the /app before printing it’s result to requirements.txt followed by installing all the packages listed on there.

Docker Compose

  • Easily start the entire application using docker-compose up.
  • Mount volumes from the local filesystem to the container with a single line in the YAML definition.
  • Only restart the containers that have changes making the boot time much more faster.
  • It starts by defining the Docker Compose version followed by defining the services one by one.
  • The first service known as db is a service for the database. As seen above it uses the image of the latest postgres as it’s images.
  • volumes are the preferred mechanism for persisting data generated by and used by Docker containers. It’s basically directories and files that exist on the host system that is connected with the container.
  • The restart on the service is used just to make sure the service is restarted when there are any changes.
  • The environment line and the ones below them are environment variables used for the service. In this particular case the ${USER} is for the docker-compose.yml to use the environment variable on the host, this is due to how a permission issue that may occur. For more detail look here.
  • The web line defines the second container of the application.
  • build step tells Docker Compose to build the current path with docker build, implying that there is a Dockerfile in the current path and that should be used for the image.
  • volume is the same thing as in the previous service, it define the filesystem mapping between the host and the container. So is environment which set the environment variables for the service.
  • depends_on express dependency between services. In this particular case the db service will start before the web service and will be stopped after the web service is stopped.





Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Building the Next Generation Web3

Test Automation

DigiFinex 22nd AMA | The XDC Network — A Layer 1 Hybrid Blockchain with a Growing Open Ecosystem

Announcement: X-engine Gleam Contest Winner

AArch64 Instruction Set

Exporting AWS RDS Snapshot to S3

Bringing Tech to HR: An Experiment in Programming

How to deploy a Jovo project with AWS CloudFormation and CI/CD

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


More from Medium

Custom Pagination in React using ReactPaginate

Git — For Dummies (Hopefully)

NoColor bug on unfilled objects

Why Should I do TDD?