Featuring:
- Docker v1.17.x
- Docker Compose v1.12.0
- Python 3.6 (With an virtul environment)
Blog post -> https://realpython.com/blog/python/django-development-with-docker-compose-and-machine/
- Start new machine -
docker-machine create -d virtualbox dev;
- Build images -
docker-compose build
- Start services -
docker-compose up -d
- Create migrations -
docker-compose run web /usr/local/bin/python manage.py migrate todo
- Grab IP -
docker-machine ip dev
- and view in your browser
- Start a python virtul environment,
pip install docker-compose
- Point docker to VM (you may need to start the vm
docker-machine start dev
),eval $(docker-machine env dev)
- build images -
docker-compose build
- Start services -
docker-compose up -d
- Create Database in postgres -
psql -h 192.168.x.x -p 5432 -U postgres
create database my_db
\l
check List of databases. - Create migrations -
docker-compose run web python manage.py migrate
requirements.txt is update. docker-compose.yml is update. production.yml is not update. If you have old pgdata volume, remember delete it, or your will get errors.
postgres_1 | FATAL: database files are incompatible with server
postgres_1 | DETAIL: The data directory was initialized by PostgreSQL version 9.5, which is not compatible with this version 9.6.2.
docker-compose down
won't delete volumes! You should do it by manual.
docker-compose.yml 中的volume的路徑要用絕對路徑。
postgresql 要另建my_db
changelog
update in 2017/04/31
rm -rf static
Executeexport $(cat .env)
thenpython manage.py collectstatic
Django static dircetly serve by nginx, so I chaged nginx Dockerfile. In docker-compose, nginx add volume from web/static to /static
update in 2017/04/16. Dockerfile of nginx changed. Dockerfile of web update to python:3.6