0Pricing
Django Academy · Lesson

Entrypoints, Migrations, and collectstatic

Run startup steps inside the container.

Entrypoints, Migrations, and collectstatic is a free Django Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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. ✅

Frequently asked questions

Is the “Entrypoints, Migrations, and collectstatic” lesson free?

Yes — the full text of “Entrypoints, Migrations, and collectstatic” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.

What will I learn in “Entrypoints, Migrations, and collectstatic”?

Run startup steps inside the container. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Django Academy?

No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Entrypoints, Migrations, and collectstatic” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Django Academy lesson?

Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Writing a Django Dockerfile
  2. docker-compose with Postgres and Redis
  3. Entrypoints, Migrations, and collectstatic
  4. Production Image Best Practices
← Back to Django Academy