Project will use docker and docker-compose, so please make sure that docker was installed and ran
- Clone project
git clone https://github.com/pogossian/docker_django_mysql.git project_name
- Go to cloned directory and remove old .git directory
cd project_name
rm -rf .git/
- Initialize a new version control.
git init
-
Review and update
requirements.txt
-
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 .
- Change mysql root password in
docker-compose.yml
- MYSQL_ROOT_PASSWORD=newpass
- 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',
}
}
- Run compose
docker-compose up -d
- Django will run as soon as mysql be ready (if you want you can watch to running proccess
docker-compose logs
)
- Create superuser
docker exec -it project_name_www_1 python3 manage.py createsuperuser
- 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