Git Product home page Git Product logo

dockerize-django-todo-app's Introduction

Dockerizing a Django Todo App with Docker Compose

This repository contains a Django Todo App that can be easily containerized using Docker Compose. The Docker Compose configuration allows you to run both the Django Todo App and a MySQL database within separate containers.

Prerequisites

Before getting started, ensure that you have the following prerequisites installed on your machine:

  • Docker
  • Docker Compose

Dockerizing with Docker Compose

Steps to Dockerize the Todo App using Docker Compose:

  1. Clone this repository to your local machine:
    git clone <repository_url>
  2. Create the docker-compose.yml file in the root directory and add configuration.
    (Here, it sets up a MySQL container along with the Django Todo App container. We will deep dive into this to understand a docker-compose file and it's configurations)
  3. Build and run the containers using Docker Compose:
    docker-compose up

Understand docker-compose.yml

Make sure you have correct indentation as indentation and spaces matters in yml file. Below configurations are added in this To Do applications docker-compose.yml, Let's understand each line by line.

version: "3.9"
services: 
 django_todo_app:
  container_name: "django-todo-app"
  build : .
  ports:
    - 8000:8000
  volumes:
    - django_todo_volume:/app
 mysql_db:
  container_name: "django-mysql-db"
  image: mysql:5.7
  ports:
    - 3306:3306
  environment:
    MYSQL_ROOT_PASSWORD: "test@123"
volumes:
 django_todo_volume:

version

In version, we have to mention the version of language which you are using in your application. As django todo app is a python application I have mentioned python version 3.9

services

Under services we specify the services which we have to run (there can be one or multiple services)

  1. django_todo_app: This is todo application where I have code base. Inside this I have specified its related commands & specifications. Let's look into it.

    container_name: Give name to your container. Here I have given container name as django-todo-app

    build: This builds or rebuild image & add all configs for the services to create a container.

    ports: Specify on which port you want to run service. It binds local port to remote server port. I am running my django todo service on 8000 and binding same to run on server.

    volumes: Bind volume for the container of service.

  2. mysql_db: Adding a service for mySQL database.

    container_name: Specify container name for service.

    image: It will pull MySQL image with 5.7 tag from dockerhub.

    ports: By default, mySQL run on port 3306, hence binding same to the server.

    environment: Here we have to pass environment variable like mySQL password.

    MYSQL_ROOT_PASSWORD: "your_password"

volumes

Declare volume which will get bind to the service.


Docker compose up

Now, with the below command, you are now ready to build and execute your docker-compose.yml, It creates containers for mentioned services.

docker-compose up

You can run in detached mode by adding -d flag.

docker-compose up -d

After all, You can check all your running containers with

docker ps

dockerize-django-todo-app's People

Contributors

sneha-tarnekar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.