0Pricing
Django Academy · レッスン

Entrypoints、Migrations、collectstatic

コンテナ内で起動時の処理を実行します

「Entrypoints、Migrations、collectstatic」はCoddyKit上の無料Django Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDjango Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Django Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Startup Steps Matter

Before serving traffic, a container often needs to run migrations and gather static files. Let's automate those startup steps. ⚙️

What an Entrypoint Is

An entrypoint is a script that runs every time the container starts, right before your main command takes over.

Write the Script

Create entrypoint.sh with a shebang line, so the container knows to run it with the shell.

#!/bin/sh
set -e

Apply Migrations on Boot

Run migrate inside the entrypoint, so your database schema is always current when the app starts.

python manage.py migrate --noinput

Gather Static Files

Run collectstatic to copy CSS and JS into one folder that your server can serve in production.

python manage.py collectstatic --noinput

Hand Off with exec

End the script with exec so your app becomes process 1 and receives stop signals cleanly.

exec "$@"

Make It Executable

Set the script as executable in your Dockerfile so the container can actually run it on startup.

RUN chmod +x entrypoint.sh

Wire It in the Dockerfile

Point ENTRYPOINT at your script, then keep CMD as the command it should run last.

ENTRYPOINT ["./entrypoint.sh"]
CMD ["gunicorn", "config.wsgi"]

Why --noinput

The --noinput flag stops Django from pausing for prompts, which is essential for unattended container startups.

Wait for the Database

Postgres may boot slowly, so it helps to wait for the db port before migrating to avoid connection errors.

until nc -z db 5432; do sleep 1; done

Watch the Logs

Use docker compose logs to confirm migrations ran and static files were collected on startup.

docker compose logs -f web

Quick Check

Why end an entrypoint script with exec on the main command?

Recap

Your entrypoint now runs migrate and collectstatic with --noinput, waits for the db, then execs the app as PID 1. Boot-ready every time. ✅

よくある質問

「Entrypoints、Migrations、collectstatic」レッスンは無料ですか?

はい。「Entrypoints、Migrations、collectstatic」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Django Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Django Academyコースには全4レッスンが含まれています。

「Entrypoints、Migrations、collectstatic」で何を学びますか?

コンテナ内で起動時の処理を実行します ブラウザで直接実行するハンズオンコードでDjango Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Django Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDjango Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。

「Entrypoints、Migrations、collectstatic」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDjango Academyレッスンでコードを書いて実行できますか?

はい。すべてのDjango Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. Django Dockerfileの作成
  2. PostgresとRedisを使うdocker-compose
  3. Entrypoints、Migrations、collectstatic
  4. 本番イメージのベストプラクティス
← Django Academyに戻る