Apple Container Django Apps

Apple's Container is an open source command-line tool for running Linux containers natively on Apple Silicon Macs. It uses lightweight virtual machines to provide strong isolation without relying on Docker Desktop. This post walks through how to containerize and run a simple Django app.

The Dockerfile

Every container starts with a Dockerfile. The slim variant of the official Python 3.14 image to keep the image size small.

FROM python:3.14-slim

WORKDIR /app

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

COPY . .

RUN mkdir -p /data

EXPOSE 8000

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

Running the App with Apple Container

Start the container system. This initializes the Apple Container daemon and the underlying VM infrastructure. You only need to do this once per session.

container system start

Build the image. This reads the Dockerfile in the current directory and produces a local image tagged project-name.

container build -t project-name .

Set environment variables. Django requires a secret key and a few other settings at runtime. We generate a key on the fly using Python's secrets module and DJANGO_ALLOWED_HOSTS.

export DJANGO_SECRET_KEY="$(python3 -c 'import secrets; print(secrets.token_urlsafe(50))')"

export DJANGO_ALLOWED_HOSTS=localhost

Run the container. This is the main command. Breaking down the flags:

  • --name web gives the container a stable name so we can reference it by name later.
  • -p 0.0.0.0:8000:8000 maps port 8000 on the host to port 8000 inside the container, making the app accessible at http://localhost:8000.
  • -v sqlite_data:/data mounts a named volume at /data so the SQLite database survives container restarts.
  • -v ./:/app bind-mounts the current project directory into the container, enabling live code reloading without rebuilding the image.
  • The -e flags pass the environment variables we set above into the container.
container run \
--name web \
-p 0.0.0.0:8000:8000 \
-v sqlite_data:/data \
-v ./:/app \
-e DJANGO_SECRET_KEY="${DJANGO_SECRET_KEY}" \
-e DJANGO_DEBUG="${DJANGO_DEBUG:-False}" \
-e DJANGO_ALLOWED_HOSTS="${DJANGO_ALLOWED_HOSTS:-localhost}" \
project-name

Stop and clean up. When you are done, stop the running container and remove it. The named volume sqlite_data is preserved, so your database remains intact for the next session.

container stop web && container rm web

Shut down the container system. This stops the underlying VM and frees the associated resources.

container system stop