DEV Community

Cover image for Django & Docker - SQLite, MySql, and PostgreSQL samples
Sm0ke
Sm0ke

Posted on β€’ Originally published at blog.appseed.us

17

Django & Docker - SQLite, MySql, and PostgreSQL samples

Hello coders!

This article mentions a few open-source Django samples that bundle Docker with different database engines: SQLite, MySql, and PostgreSQL. The projects might be useful to developers that what to switch from the minimal SQLite to a more powerful DB engine like PgSQL or MySql. Being released under the MIT License, the related Docker scripts can be copied and incorporated into other projects.

Thanks for reading!


Django & Docker SQLite

This sample is the most simple one. The SQLite database is created by Django during the migration and does not require any additional Docker layer.

Once the product is downloaded, the app can be started via a single command:

$ docker-compose up --build 
Enter fullscreen mode Exit fullscreen mode

During the execution, the Docker scripts prepare the environment, install the modules and migrate the database. In the end, the app should be up & running as this LIVE Demo of the product.

Django Material Kit - Docker & SQLite set up.


Django & Docker, MySql

Compared to the SQLite version, this sample requires a manual migration of the database.

Here is the full set up of the project.

Step 1 - Download the sources

$ git clone https://github.com/app-generator/sample-docker-django-mysql.git
$ cd sample-docker-django-mysql
Enter fullscreen mode Exit fullscreen mode

Step 2 - Execute the Docker set up

$ docker-compose up --build 
Enter fullscreen mode Exit fullscreen mode

Step 3 - Migrate DB & create SuperUser

$ docker-compose run --rm appseed-app python manage.py migrate
$ docker-compose run --rm appseed-app python manage.py createsuperuser
Enter fullscreen mode Exit fullscreen mode

Step 4 - Access the app in the browser

Visit http://localhost:5085 in your browser. The app should be up & running.

Django, Docker & MySql - Free Sample.


Django, Docker & PgSQL

The last sample uses PostgreSQL for app persistence, a popular DB engine heavily used in production.

πŸ‘‰ Django, Docker & PgSQL - source code

The product can be started and used in a local environment by typing the same commands as for the MySql version:

  • βœ… Download source code
  • βœ… Execute docker-compose up --build
  • βœ… Migrate the database
  • βœ… Create SuperUser (optional)

Django, Docker & PostgreSQL - Free Sample


All samples are built on top of Material Kit, an amazing design provided for free by Creative-Tim. Here is the product description, copied from the official page:

πŸ‘‰ Material Kit - Open-Source Bootstrap 5 design

Designed for those who like bold elements and beautiful websites, Material Kit is ready to help you create stunning websites and web apps. The product is built on top of Bootstrap 5 with over 60 frontend individual elements, like buttons, inputs, navbars, nav tabs, cards, or alerts, giving you the freedom of choosing and combining.

Material Kit - Free Bootstrap 5 Kit


Thanks for reading! For more resources, please access:

  • πŸš€ Free support provided by AppSeed (email & Discord)
  • πŸ‘‰ More free apps crafted in Flask, Django, and React

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (6)

Collapse
 
raibtoffoletto profile image
RaΓ­ B. Toffoletto β€’

Nice work!! Thanks for sharing!!

Collapse
 
sm0ke profile image
Sm0ke β€’

ty Rai

Collapse
 
uithemes profile image
ui-themes β€’

Nice work.
Thanks for coding & sharing the projects.

Collapse
 
sm0ke profile image
Sm0ke β€’

πŸš€πŸš€

Collapse
 
crearesite profile image
WebsiteMarket β€’

The PostgreSQL set up helps.
Is possible to move the migration command inside scripts?

Collapse
 
sm0ke profile image
Sm0ke β€’

Yes, but the set up should use another pattern when entrypoint.sh handles the commands.
πŸš€πŸš€

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post