Skip to content

Dockerize Python Apps

Docker enables developers to pack applications into containers that run as instances of a docker image and contain their own operating system as well as all the necessary dependencies. This makes it easier, simpler and safer to build, deploy and manage your apps.

docker compose

docker compose enables running & management of a multi-container application in a simple way using the YAML file (docker-compose.yml) defining all the required services.

For out example we will use 2 services:

django application

postgres database

basic project setup



In the dockerfile we will use the requirements.txt file to install all the necessary packages.

Before, make sure you have the following packages installed:

Next create the requirements.txt file:

pip freeze>requirements.txt


Dockerfile for our python/django app:


The docker-compose file including two services:

web(django web app) and db (postgres db)

Commands to execute

Now run the containers:

docker-compose up -d

Stop the containers:

docker-compose down

View the logs of a container:

docker-compose logs <service_name>

List the running containers:

docker ps

Get inside the web container to execute other commands (i.e. createsuperuser)

docker exec -it <container_id> /bin/sh


  1. One important thing is that when you find yourself searching for a education loan you may find that you will need a co-signer. There are many conditions where this is true because you will find that you do not possess a past credit ranking so the lender will require that you’ve someone cosign the money for you. Good post.

  2. I appreciate, cause I found just what I was looking for. You have ended my 4 day long hunt! God Bless you man. Have a nice day. Bye

    • You’re welcome 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *