Django-PostgreSQL(Docker-Compose)
自分用の勉強メモ
自分用 : Docker folder 11
実行環境構築
フォルダ構成
C:.
│ docker-compose.yml
│ Dockerfile
└─ requirements.txt
docker-compose.yml
docker-compose.yml
version: "3"
services:
db:
image: postgres
ports:
- "5432"
environment:
- POSTGRES_DB=db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
links:
- db
dockerfile
FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/
requirements.txt
Django
psycopg2
実行する
powershell
docker-compose run web django-admin.py startproject composeexample .
フォルダ構成
C:.
│ docker-compose.yml
│ Dockerfile
│ manage.py
│ requirements.txt
│
└─composeexample
settings.py
settings.pyc
urls.py
urls.pyc
wsgi.py
wsgi.pyc
__init__.py
__init__.pyc
設定を修正する
\composeexample\settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
実行する
powershell
docker-compose up
確認する
http
http://localhost:8000/