(: September 23, 2019)

In this tutorial, I will show you how to set up a Docker environment for your Django project when still in the development phase. Although I am using Ubuntu 18.04, the steps remain the same for whatever Linux distro you use with exception of Docker and docker-compose installation.

In any typical software development project, we usually have a process of development usually starting from the developer premise to VCS to production. We will try to stick to the rules so that you understand where each DevOps tools come in.

DevOps is all about eliminating the yesteryears phrase; “But it works on my laptop!”. Docker containerization creates the production environment for your application so that it can be deployed anywhere, Develop once, deploy anywhere!.

.td_uid_2_5d909e0df3837_rand.td-a-rec-img{text-align:left}.td_uid_2_5d909e0df3837_rand.td-a-rec-img img{margin:0 auto 0 0}

Install Docker Engine

You need a Docker runtime engine installed on your server/Desktop. Our Docker installation guides should be of great help.

How to install Docker on CentOS / Debian / Ubuntu

Environment Setup

I have set up a GitHub repo for this project called django-docker-dev-app. Feel free to fork it or clone/download it.

First, create the folder to hold your project. My folder workspace is called django-docker-dev-app. CD into the folder then opens it in your IDE.


In a containerized environment, all applications live in a container. Containers themselves are made up of several images. You can create your own image or use other images from Docker Hub. A Dockerfile is Docker text document Docker reads to automatically create/build an image. Our Dockerfile will list all the dependencies required by our project.

Create a file named Dockerfile.

$ nano Dockerfile

In the file type the following:

#base image
FROM python:3.7-alpine

LABEL Author="CodeGenes"

# The enviroment variable ensures that the python output is set straight
# to the terminal with out buffering it first

#copy requirements file to image 
COPY ./requirements.txt /requirements.txt

#let pip install required packages
RUN pip install -r requirements.txt

#directory to store app source code
RUN mkdir /app

#switch to /app directory so that everything runs from here

#copy the app code to image working directory
COPY ./app /app

#create user to run the app(it is not recommended to use root)
#we create user called user with -D -> meaning no need for home directory
RUN adduser -D user

#switch from root to user to run our app
USER user

Create the requirements.txt file and add your projects requirements.


Create the app folder that will hold the source code. Now we are ready to build our image!

$ mkdir app

Open a terminal in your project and type the following command to build our image:

 $ docker build .

At the end tells Docker to check for Dockerfile in the same directory, if you had the file in a different location, we would have written the path to that file. Docker will then call the necessarily required images from the Docker Hub to create your image.

Using Docker Compose

From Docker docs; Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Install Docker Compose on Linux

Because our project will require a lot of services in the future, it is better to create a multi-container environment for it. For example, we might require a container to host our front end, another to host a database and another to host a backend when we switch to a microservice architecture. We will create a docker-compose file that will define the various services and containers our project will require.

Create a file named docker-compose.yml

version: "3"
      context: .
      - "8000:8000"
      - ./app:/app
    command: >
      sh -c "python manage.py runserver"

Note the YAML file format!!! We have one service called ddda (Django Docker Dev App).

We are now ready to build our service:

 $ docker-compose build

After a successful build you see: Successfully tagged djangodockerdevapp_ddda:latest

It means that our image is called djangodockerdevapp_ddda:latest and our service is called ddda

Now note that we have not yet created our Django project! If you followed the above procedure successfully then Congrats, you have set Docker environment for your project!. Next, start your development by doing the following:

Create the Django project:

 $ docker-compose run ddda sh -c “django-admin.py startproject app .”

To run your container:

$ docker-compose up

Then visit http://localhost:8000/

Make migrations

$ docker-compose exec ddda python manage.py migrate

From now onwards you will run Django commands like the above command, adding your command after the service name ddda.

That’s it for now. I know it I simple and there are a lot of features we have not covered like a database but this is a start!

The project is available on GitHub here.

More on Docker:

How To Export and Import Docker Images / Containers

How To Install Harbor Docker Image Registry on CentOS / Debian / Ubuntu

How To run Local Kubernetes clusters in Docker

.td_uid_4_5d909e0df3a9e_rand.td-a-rec-img{text-align:left}.td_uid_4_5d909e0df3a9e_rand.td-a-rec-img img{margin:0 auto 0 0}
  • Bitcoin Quiz of the Week: 19th – 23rd Oct
  • Bash Shell Count Number of Characters In a String or Word
  • Yes, This Wu-Tang Clan-Themed Cryptocurrency Is Actually Happening
  • Coinbase US Government Liaison Leaves for Banking Role
  • How to Install mod_fcgid on cPanel’s EasyApache 4 with CloudLinux
  • Facebook’s Libra Is a ‘Wake-Up Call’ for Regulators, Says ECB Policymaker
  • BMW Test Drives Blockchain for Car Mileage Tracking
  • US Lawmakers Want FinCEN Mandate to Explicitly Cover Crypto
  • After Millions Raised, the SAFT Is Alive But Who Knows How Well
  • Payments Giant Qiwi is Building a Blockchain Replacement for its Core Database
  • Litecoin Prices Jump 70% as Market Cap Adds Over $100 Million
  • DigitalOcean vs AWS
  • How to Cherry Pick in Git
  • Gyft Forced to Abruptly End Walmart Gift Card Support
  • Qmail allow email from my own domain (particular domain) only
  • SXI LLC Company
    SXI.IO is a global Blockchain software company, specialized in developing white label crypto exchange platforms , Wallet platforms, ICO platforms, Token Erc20 .....
    Fully Managed VPS Fully Managed VPS Fully Managed VPS

    You Might Also Enjoy NewS Post

    Best Free Web Hosting 2020

    Free Hosting 1GB $0.00 USD/mo Disk space 1GB Traffic 10GB/Month Domains 2 Plesk Cpanel Databases 10 Free 12 Month https://my.sxi.io/cart.php?a=add&pid=196

    02/05/2020 READ MORE