1
0

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 5 years have passed since last update.

docker-composeでDjangoの空プロジェクトを3分で作成する

Last updated at Posted at 2019-10-29

ちょっとしたアプリを作ることになって、
最近docker勉強中なのでアウトプット。

DBのコンテナも接続する予定ですが、
一旦djagoコンテナの生成までということで投稿。


ローカルの任意の場所に
compsoeファイルを作成する。

docker-compose.yaml
version: '3'
services:
  django:
    build:
      context: ./django
    ports:
      - "8000:8000"
    volumes:
      - ./src:/app/src
    command: python manage.py runserver 0.0.0.0:8000
    tty: true

composeファイルと同階層にdjangoフォルダを作成し、
その中に以下の2ファイルを作成する。

  • Dockerfile
Dockerfile
FROM python:3.7.3
ENV LANG en_US.utf8

WORKDIR /app/src
ADD requirements.txt /app/src
RUN apt-get update
RUN pip install -r requirements.txt
  • requirements.txt
requirements.txt
django==2.2

composeファイルのあるパスへ移動し、
以下のコマンドでプロジェクトを生成する。
(今回はプロジェクト名をblogとして作成)

docker-compose run django django-admin startproject blog .

これで、ローカルのcomposeファイルと同じ階層にsrcフォルダが作成され、
その配下にdjangoのprojectファイルが生成される。

試しに、コンテナを起動し、http://localhost:8000/にアクセスして、
djangoが起動していることを確認する。

スクリーンショット 2019-10-29 20.06.12.png

これで空のdjangoプロジェクトが乗ったコンテナが作成できました。

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?