LoginSignup
0
0

[忘備録]dockerによるdjangoの起動方法

Last updated at Posted at 2023-05-21

dockerでdjangoを起動するときの方法

すぐに忘れてしまうのでここに忘備として置く。

dockerfile


FROM python:3.8.12

# 必要なパッケージやライブラリをインストール
RUN pip install django==4.0.2

# コンテナ内に作業ディレクトリを作成
WORKDIR /app

# ホストマシンの特定のディレクトリをコンテナ内のディレクトリにマウント
VOLUME [" C:/Users/自分の名前/Documents/python/django4:/app"]

# コンテナ内で実行するコマンド
CMD ["python", "blogproject/manage.py", "runserver", "0.0.0.0:8000"]

dockerの構築

docker build -t my-django-app .

dockerの起動とdjangoのrun

docker run -it -p 8000:8000 -v C:/Users/自分の名前/Documents/python/django4:/app my-django-app

dockerコンテナ内に入る

psで自分の入りたいコンテナIDを探してから、execで起動する。

docker ps

docker exec -it コンテナID bash

"the docker daemon is not running"と表示したとき

docker desctopを起動せよ。

PS C:\Users\自分の名前\Documents\python\django4> docker build -t my-django-app .
ERROR: error during connect: this error may indicate that the docker daemon is not running: Get "http://%2F%2F.%2Fpipe%2Fdocker_engine/_ping": open //./pipe/docker_engine: The system cannot find the file specified.

bootstrapが読み込まれなかったとき

Django4 Webアプリ開発 実装ハンドブックの第4章で、ダウンロードされたindex.htmlを改造したとき、cssやjsが読み込まれず、文字のみが表示される場合がある。このときは/blogproject/blogproject/setting.pyで以下の様にする。

STATIC_URL = 'static/'

STATIC_URL = '/static/'

0
0
1

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