rx-36

Basic Django Development Setup 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; you don't need a separate web server container like Nginx. 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 minimal 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 dive into the details of each step.

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

Avoid Using the Same Port

That concludes this basic setup guide. You can use it as a foundation for future articles here and for quickly spinning up development environments in everyday app work. Feel free to adapt it in your own projects.

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