My Django Docker image

A description, step by step of how I builded my docker django image, how i loaded it on docker hub and how can be use it and customized.

STEP 1 — Create Dockerfile and push it on Docker Hub

In a folder I create a file named Dockerfile and an another named requirements.txt


FROM python:2.7
LABEL maintainer "Pierangelo Orizio <>"
RUN apt-get update -qq && apt-get install build-essential g++ flex bison gperf ruby perl \
mysql-client \
libsqlite3-dev libmysqlclient-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev \
postgresql-client \
libpng-dev libjpeg-dev python libx11-dev libxext-dev -y
RUN mkdir /code
ADD requirements.txt /code/
COPY . /code
RUN pip install -r requirements.txt
#ADD . /code/
RUN startproject djangoproject
RUN mkdir /code/djangoproject/media && mkdir /code/djangoproject/static
VOLUME /code
WORKDIR /code/djangoproject
CMD ["python", "", "runserver", ""]



from terminal inside the folder, I build the local image:

docker build -t django .

tag the local image:

docker tag django pierangelo1982/django

sign in to your docker account:

docker login

push the image on your Docker Hub account:

docker push pierangelo1982/django

P.S: pierangelo1982 is my docker account username, change it with yours.

STEP 2 — create and implement container

pull the image:

docker pull pierangelo1982/django

For work and implement our project, we have need to share the project folders of the container on our local host. For do that we have need to build a volume and copy the file.

create a volume:

docker volume create --name django-volume

connect the volume to the container for can copy the project folder

docker run --name django-test \
-v django-volume:/code \
-p 8000:8000 \
-d pierangelo1982/django

copy project folders in your host

docker cp django-test:/code ~/my/local/path/myfolder

remove the container

docker rm -f django-test

recreate the container with the volume that point to our local folder where before we have copy the folders of the project.

docker run --name django-test \
-v ~/my/local/path/myfolder:/code \
-p 8000:8000 \
-d pierangelo1982/django

Using django and python commands:

docker exec django-test python

how install new packages:

docker exec django-pierangelo pip install

Source code:

Docker Hub:

Subscribe my weekly newsletter:

a selection of articles about Start up, AI, technology, programming languages, devops etc…