GithubHelp home page GithubHelp logo

dockerized-django-nginx-mysql's Introduction

Demo Django Application with MYSQL and Nginx Reverse Proxy.

Dockerize-01


Table of Contents

  • Prerequisites

  • How to build

  • Configuration


Prerequisites

Make sure you have downloaded these prerequisites before we start


How to build

  1. Clone the repository to your local machine

    git clone https://github.com/jodeh/Dockerized-Django-Nginx-MYSQL.git
    cd Dockerized-Django-Nginx-MYSQL
    
  2. Before we start to run the containers, we need to make a network to let the containers to connect with each other

    docker network create --subnet 10.0.0.0/24 custom-network
    
  3. Now lets run our mysql container :

    docker run -d --network custom-network --ip 10.0.0.15 --hostname mysql-database -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=djangodb mysql
    
  4. Build the Django image and run the container

    cd /Django
    docker build -t django-app .
    docker run -d --network custom-network --ip 10.0.0.10 --hostname django django-app
    
  5. Build the nginx image and run it

    cd /nginx
    docker build -t nginx-reverse-proxy .
    docker run -d --network custom-network --ip 10.0.0.5 -p 80:80 --hostname nginx nginx-reverse-proxy  
    
  6. Create user in mysql .

    docker exec -it <mysql container id> bash
    
    $ mysql -p
    > CREATE USER 'jodeh'@'%' IDENTIFIED BY 'password';
    > GRANT ALL PRIVILEGES ON *.* TO 'jodeh'@'%' WITH GRANT OPTION;
    > FLUSH PRIVILEGES;
    
  7. Migrate tables to the new database

    docker exec -it <django container id> bash
    cd ~/mysite
    python3 manage.py migrate
    
  8. Now go back to mysql container to check tables

    docker exec -it <mysql container id> bash
    
    $ mysql -p
    > SHOW DATABASES;
    > USE djangodb;
    > SHOW TABLES;
    

    Tables must be shown like this.

    djangodb

  9. Finally Check The Connectivity

Django


Configuration

  • We can configure django settings by editting ./django/mysite/settings.py file
  • The proxy pass and the server name can be configured by editting ./etc/nginx/conf.d/default.conf file

dockerized-django-nginx-mysql's People

Contributors

jodeh 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.