Skip to main content

Run Django with Docker

 Assumptions: We’ll be working with a Django application, Some experience working with a Django application might be needed and you have Docker & Docker Compose installed.

Packaging an Application Into An Image

This OS-level virtualization provided by Docker helps us mirror the application and platform into a docker file. The docker file should be placed at the root of the Django project.

Docker images also allow you to define metadata and define more options to help operators run the application according to your application needs.

Setting Up A Docker-compose.yml File

For clarity, Docker Compose solves the problem of running multi-container applications at once. You thus can set the desired amount of containers counts, their builds, services, and volumes, and then with a single set of commands, you can build, run, and configure all the containers.

According to Docker-compose Docs Using Compose is basically a three-step process:

  • Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
  • Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
  • Run docker-compose up and Compose starts and runs your entire app.

it is also located in the root directory of the Django application. The Docker environment variable file .env is necessary when you're creating complex containers or Database service for deployments.

So let’s say you have your .env file (that's the full name of the file, by the way) located in the same directory that houses your docker-compose.yml file. In the .env file, you have on these lines:

A simple docker-compose.yml looks like this:

We’re all set now, lets build and run our container using this simple command :

Comments

Popular posts from this blog

Django Learing Resources

Django is one of the most popular web application framwork. This framwork is based on Python. Django is Batteries included Framwork which means all the tools and basic requirements and features which are commonly required to build performant and scalable web applications such as  Security, Logging-system and different software packages are already build into Django. So it does not require to build this common requirements to be build from the groundup. Some advantages of django: Rapid Development: Django was designed to allow developers to build web applications quickly and efficiently. It provides a range of tools and features that make it easy to develop and deploy complex applications, such as an admin interface, ORM, URL routing, and more. Scalability: Django is designed to scale up to handle large amounts of traffic and data, making it a good choice for large-scale, complex web applications. Security: Django has a strong focus on security and provides several built-in security...

Create a Change Password View in Django

Creating a “change password” feature is an essential part of any web application’s security system. In Django, creating a “change password” view is a straightforward process, and this tutorial will guide you through the steps. Step 1: Create the Change Password Form The first step is to create a form that will allow users to change their password. Here’s an example of what the form might look like: from django import forms class ChangePasswordForm(forms.Form): old_password = forms.CharField(widget=forms.PasswordInput()) new_password = forms.CharField(widget=forms.PasswordInput()) confirm_password = forms.CharField(widget=forms.PasswordInput()) The ChangePasswordForm form requires the user to input their old password, new password, and confirm password. The widget=forms.PasswordInput() attribute sets the input type to password, which will display asterisks or circles instead of plain text. Step 2: Create the Change Password View Next, create the view that will handl...