ほぼ "Getting started with Compose and Django" そのまま
(macosx10.9, boot2docker1.6.0, docker-compose1.2.0, django1.8)
インストール
boot2docker
docker-compose
boot2docker 実行
$ boot2docker init $ boot2docker start $ $(boot2docker shellinit)
ファイル
- Dockerfile
- requirements.txt
- docker-compose.yml
Dockerfile
FROM python:2.7 ENV PYTHONUNBUFFERED 1 ADD . /app/ WORKDIR /app RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED 1
これは何だ?
- https://docs.python.org/2.7/using/cmdline.html#envvar-PYTHONUNBUFFERED
requirements.txt
Django==1.8.1 psycopg2==2.6
docker-compose.yml
db: image: postgres web: build: . command: python manage.py runserver 0.0.0.0:8000 volumes: - .:/app ports: - "8000:8000" links: - db
- ports は ホスト:コンテナ内
docker-compose run
$ docker-compose run web django-admin.py startproject composeexample .
DB設定
composeexample/settings.py
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', 'USER': 'postgres', 'HOST': 'db', 'PORT': 5432, } }
runserver 起動
$ docker-compose up
$ boot2docker ip <boot2docker-ip> Running on http://<boot2docker-ip>:8000/