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

Dockerfileからコンテナ起動までをやってみる

Last updated at Posted at 2025-08-17

前置き

業務でコンテナを使うことになったので、練習がてらコンテナを起動してみる。
以前つくったDjangoのHello Worldをコンテナで起動したい。

DjangoでHello Worldをする

Dockerfileを作る

まずは、Dockerfileを作ろう
あまり細かいことは気にせず、作ってみる。

以下の記事を参考にした。

パッケージの依存関係は、requirements.txtで管理する。
以下コマンドで、作成することができる。

pip freeze > requirements.txt

Dockerfile

FROM python:3

WORKDIR /code

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

# アプリケーションのソースコードをコピー
COPY . . 

CMD ["python","manage.py","runserver","0.0.0.0:8000"]

Docker Imageを作成する

docker build -t my-django-app .

コンテナを起動する

docker run -p 8000:8000 my-django-app

結果
ブラウザからlocalhost:8000でアクセスできることを確認
image.png

Git
https://github.com/moto0206/django-hello/releases/tag/0.2.0

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