There are some condition to deploy django in docker with nginx sever.One : Already create a project and run it locally and project is complete now want to deploy in docker container

Two: Create a new project in docker container at first and after that work

Today I will share my personal experience how I deploy my in docker and I use mysql database in project.

I use the first section. At first create a project in my Ubuntu 16.4 and build full project after that I setup docker container for deployment. Try to explain well and use at least use minimum steps to easily run a project successfully.

Prerequisite:

  • Ubuntu 16.4
  • Use django 1.10
  • Use Mysql database for project
  • Docker Install

Today I just description some small steps how to deploy existing project in docker.

Already your project run successfully on your local pc. Now follow some steps to deply it

First Steps :

In Project root directory create a file name Dockerfile

In here we can tell which version of python we will use and some common packages we need in docker container we call tell to install automatically

A sample of Dockerfile:

FROM python:3.5-onbuild
RUN apt-get update
RUN apt-get install -y libmysqlclient-dev mysql-client libpq-dev libffi-dev

ENV PYTHONUNBUFFERED 1

Second Steps : Now wrire a file in root directory name docker-compose.yml

at first give a sample file after that explain
version: '2'
services:
project_db:
image: mysql:5.6
restart: always
ports:
- "3308:3306"
volumes:
- "~/.docker-data/erp:/var/lib/mysql"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: projectdb
MYSQL_USER: project
MYSQL_PASSWORD: password

project_nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
volumes:
- "./nginx/sites-enabled/:/etc/nginx/sites-enabled/"
- /www/static
volumes_from:
- project_web
links:
- project_web:project_web

project_web:
build: .
restart: always
image: project/appname
environment:
DEBUG: 'true'
volumes:
- '.:/usr/src/app'
- './assets:/usr/src/app/assets'
env_file: .env
ports:
- "8000:8000"
depends_on:
- project_db
links:
- project_db

Third steps:

create a .env file in root file.

SECRET_KEY= your secret key
DB_NAME= dbname
DB_USER= root
DB_PASS= password
DB_SERVICE= project_db
DB_PORT=3306

Forth Steps :

Now create a nginx folder in project root directory. create a Dockerfile again and create a folder name ‘sites-enabled’ here

nginx Dockerfile:

FROM nginx
RUN rm -Rf /etc/nginx/sites-enabled/*
ADD sites-enabled/ /etc/nginx/sites-enabled

In sites-enabled folder create a file name ‘prochito_erp’

sample data:
server {

}

Now run docker-compose up. It need some times to build images. Happy enjoy deploy a project