1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Django-PostgreSQL(Docker-Compose)

Last updated at Posted at 2023-01-22

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/

image.png

参考&引用:
クイックスタート・ガイド:Compose と Django

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?