Skip to content

Using docker for django development

I started to use Docker for different purposes, ranging from development to uses where a virtual machine is overkill.

Lately, I have played around with Python 3 and Django and decided to create a Docker environment where I can run the Django stuff while having the flexibility to change library versions as I need to.

You can download all the files used in this post on GitHub.

The repository had major changes, so this article got updated accordingly. (8. August 2016)

I started with the following Dockerfile:

From python:3.4.3
MAINTAINER Davide Bove <info@davidebove.com>
ENV PYTHONUNBUFFERED 1

RUN pip install django && mkdir /static
COPY django_bash_completion /etc/bash_completion.d/django_bash_completion

WORKDIR /code
CMD ["/bin/bash", "--init-file", "/etc/bash_completion.d/django_bash_completion"]

This simple container installs Django and adds bash completion for it.

If you want to run the container, you can run the given shell script with sh run_docker.sh. The script starts an interactive bash session, which offers all the python and Django tools you usually need.
When the built-in server is started, the app can be accessed on your machine with the following url: http://localhost:8000/.

Now you can start developing on your local machine, and all changes are loaded automatically into the Django runtime. You can also always quit the server manually and restart the docker container.

Note: The GitHub repository also contains a docker-compose file, which is another method to run docker containers. The Docker Compose method will be shown in another post.
The Docker-Compose method was removed, as the additional database container is not used anymore.

Published inTechnology

16 Comments

  1. Madonna Gutting

    I really can’t believe how great this site is. Keep up the good work. I’m going to tell all my friends about this place.

  2. my link

    I just want to tell you that I am just newbie to blogging and honestly liked your page. Very likely I’m planning to bookmark your website . You amazingly come with impressive posts. Thanks a lot for revealing your website.

  3. Nick

    I just want to mention I’m very new to blogging and site-building and definitely enjoyed your web page. Probably I’m going to bookmark your blog post . You actually come with great posts. Cheers for revealing your web page.

  4. bastcilkdoptb

    I love the efforts you have put in this, thankyou for all the great articles.

Leave a Reply

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