Skip to content

Latest commit

 

History

History
84 lines (54 loc) · 1.67 KB

README.md

File metadata and controls

84 lines (54 loc) · 1.67 KB

Project will use docker and docker-compose, so please make sure that docker was installed and ran

  1. Clone project
git clone https://github.com/pogossian/docker_django_mysql.git project_name
  1. Go to cloned directory and remove old .git directory
cd project_name
rm -rf .git/
  1. Initialize a new version control.
git init
  1. Review and update requirements.txt

  2. Copy existing django project to current directory or create a new project.

    it's can take a long time, because before run compose would build an image

docker-compose run --no-deps --rm www django-admin startproject project_name .
  1. Change mysql root password in docker-compose.yml
     - MYSQL_ROOT_PASSWORD=newpass
  1. Change databases to mysql in project_name/settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'db',
        'USER': 'root',
        'PASSWORD': 'newpass',
        'HOST': 'db',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}
  1. Run compose
    docker-compose up -d
  1. Django will run as soon as mysql be ready (if you want you can watch to running proccess docker-compose logs)
  1. Create superuser
docker exec -it project_name_www_1 python3 manage.py createsuperuser
  1. Try to login in admin page

P.S

use docker exec -it project_name_www_1 python3 manage.py command for working with manage.py

e.g.

docker exec -it project_name_www_1 python3 manage.py migrate - for migrate

docker exec -it project_name_www_1 python3 manage.py makemigrations - for makemigrations