Last updated
Last updated
This page explains how to Dockerize a Django application with ease. For newcomers, Django is a leading web framework crafted in Python and Docker is a virtualization software used to isolate the execution of a service or product using virtual containers.
First of all, make sure you have Docker installed and running on your machine. Refer to the official and follow the steps.
Once it's done, create a Dockerfile
file. This will contains all the commands that could be called on the command line to create an image.
Once this is done, we can build the image and run it.
You can now access your app on localhost:5000.
If you want to create multiple images and run them using the precedent Docker configuration, you'll have to create multiple Dockerfile
.
Docker Compose
saves from this by allowing you to use a YAML
file to operate multi-container applications at once and run it just with one command.
Once it's done, create a docker-compose.yml
file at the root of your project. Make sure to have an .env
file at the root of your project.
We can now remove some lines from the Dockerfile
.
And now let's use docker-compose
command to build and run the image.
And your application will be running on localhost:5000.
Django App
short info regarding the codebase
Gunicorn - the WSGI server
Nginx - a powerful HTTP proxy
Dockerfile
How to bundle the information
short description
Docker-compose
included sections - short description
Follow the official to install docker-compose
on your machine.
@please refer to the configuration implemented by the reference
sample -
sample -
How to setup a Django project to run in Docker