Skip to main content

Command Palette

Search for a command to run...

Project:Setting Up Django Todo App with Docker and Volumes

Updated
2 min read

Docker has revolutionized the way we deploy and manage applications, providing a consistent environment across different platforms. In this tutorial, we'll guide you through the process of setting up a Django Todo application using Docker and managing persistent data with volumes.

Step 1: Install Docker

First things first, make sure you have Docker installed on your instance. If not, run the following command:

sudo apt install docker.io

This will install the Docker engine on your system.

Step 2: Clone the Git Repository

Next, clone the Django Todo app repository from GitHub:

git clone https://github.com/LondheShubham153/django-todo-cicd.git

Navigate to the app directory:

cd django-todo-cicd/

Step 3: Build Docker Image

Now, it's time to build the Docker image for your Django Todo app:

sudo docker build -t django-todo-app .

Verify that the image has been created successfully:

sudo docker images

Step 4: Create and Run Docker Container

Create a container for the app:

sudo docker run -d -p 8000:8000 django-todo-app:latest

Check if the container is running:

sudo docker ps

Step 5: Set Up Volumes

To manage persistent data, create a separate directory for volumes:

mkdir volumes/django-app

Create a Docker volume:

sudo docker volume create --name django-todo-volume --opt type=none --opt device=/home/ubuntu/projects/volumes/django-app --opt o=bind

Step 6: Remove Existing Containers (Optional)

If there are any existing containers that you want to remove, you can do so by identifying their IDs using:

sudo docker ps

Then stop and remove them:

sudo docker kill container_id
sudo docker rm container_id

Step 7: Create and Run Container with Volume

Finally, create and run the container using the volume we created:

sudo docker run -d -p 8000:8000 --mount source=django-todo-volume,target=/data django-todo-app:latest

Here source is the "name of the volume" and target is the "working directory" from Dockerfile.

Your Django Todo app is now running in a Docker container, and the data is persisted using volumes. You can access your app by navigating to http://your_instance_ip:8000 in your web browser.

Further you can upload some data on app and then delete the container and re-create the container using volume, you can find the data will be available on app.

Docker simplifies the deployment process, and with volumes, you can ensure that your data remains intact even if the container is stopped or removed.

More from this blog

Vishal Parit's Blogs

13 posts