Django Dockerizing App
How to setup a Django project to run in Docker
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.
Adding Docker
First of all, make sure you have Docker installed and running on your machine. Refer to the official documentation 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.
Adding Docker Compose
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.
Follow the official documentation to install docker-compose
on your machine.
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.
Dockerize a production-ready app
@please refer to the configuration implemented by the reference Django Codebase
Django App
short info regarding the codebase
Gunicorn - the WSGI server
Nginx - a powerful HTTP proxy
Dockerfile
How to bundle the information
short description
sample - Dockerfile
Docker-compose
included sections - short description
sample - docker-compose.yml
Last updated
Was this helpful?