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 <firstname.lastname@example.org> 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.