Basic setup for running Django with Docker

Hello everyone! (`・ω・´)ゞ Today, I'll show you the easiest way to set up a Django development environment using Docker. Many technical blog posts about Dockerizing Django that you find online aren't specifically tailored for development and often include configurations that are overkill for a development setup.

For instance, during the development phase, containerizing only Django and the database is sufficient; a local web server works perfectly fine. This minimal configuration allows for a quick setup so you can focus on writing code.

This article summarizes a simple development environment setup with Docker.

We'll be creating just three things: a Dockerfile, a docker-compose.yaml file, and a very simple Django application. Let's begin!

Note: I'm using PyCharm, but the basic setup is almost the same regardless of which IDE you're using (VS Code, etc.).

1. Create a Django project

2. Create Dockerfile and docker-compose.yaml files

3. Create a requirements.txt file

4. Place environment variables in the settings.py file

5. Build the Dockerfile

6. Confirm Building Django

7. Make the manage.py is available

8. Adding template, static folder, and STATICFILES_DIRS

We've now completed the minimum setup for our Django project. However, there's still more to do before we can add an application.

Let's create a very simple application that just displays "hello world" in a template.

Here are the steps we'll follow:

  • 8-1. Create a new application in the project.
  • 8-2. Create a template folder in the root directory and add a template such as `base.html`.
  • 8-3. Create a static folder in the root directory to add CSS and js files.

Let's walk through the details of these steps.

9. Add minimal code to urls.py and views.py to display hello world.

Avoid Using the Same Port

That's all. This basic setup will be used as a premise in other articles on this blog. It is also helpful for quick environment creation in everyday app development. Please make use of it!

Lastly, the GitHub repository for this project can be found here.