Docker — Dockerfile, Compose, Model Runner, CLI
docker-tools).
View source on GitHub →What this skill covers
Docker as I use it day to day on Drupal, PHP and AI projects: building images with a Dockerfile, running multi-container stacks with Docker Compose, serving local AI models with Docker Model Runner (docker model), and the docker commands for inspecting, debugging and cleaning up. It is a working reference, not an introduction — for the full option list see the official Docker documentation
.
When to use it
- Containerizing a Drupal/PHP or Python application, or making an existing image smaller and faster to build
- Writing or editing a
compose.yaml— adding a service, a healthcheck, a dev/prod split - Running an LLM locally with
docker modeland connecting an app (or the Drupal AI module) to it - Debugging containers that won’t start, can’t reach each other, or eat the disk
Learn the actual setup first
Before changing anything, read what the project already has — don’t assume service names, ports or volumes:
Dockerfile(ordocker/*/Dockerfile) and.dockerignorecompose.yaml/docker-compose.ymlplus anycompose.override.yamlor-ffiles the project uses.env— referenced as${VAR}; it holds secrets, so read it, never commit itdocker compose config— the final merged configuration Compose will actually run
Dockerfile
A lean, cache-friendly image for a PHP application:
# syntax=docker/dockerfile:1
FROM composer:2 AS vendor
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-scripts --prefer-dist --no-interaction
FROM php:8.3-fpm-alpine
RUN apk add --no-cache icu-libs libzip \
&& apk add --no-cache --virtual .build-deps icu-dev libzip-dev $PHPIZE_DEPS \
&& docker-php-ext-install intl opcache pdo_mysql zip \
&& apk del .build-deps
WORKDIR /var/www/html
COPY --from=vendor /app/vendor ./vendor
COPY . .
USER www-data
What makes it work:
- Order layers by how often they change. Dependency manifests first,
composer install, then the source — a code change no longer reinstalls every package. - Multi-stage builds. Build tools stay in the first stage; the final image carries only the runtime and the result.
- Pin the base image (
php:8.3-fpm-alpine, notlatest) so builds are reproducible. .dockerignore— keep.git,node_modules,vendor,.envand local files out of the build context; it speeds up the build and keeps secrets out of the image.- Don’t run as root — switch with
USERonce the files are in place. - No secrets in
ARG/ENV— they stay in the image history. UseRUN --mount=type=secret,id=...for build-time secrets. - One process per container — php-fpm and nginx are two services, not one image with a supervisor.
Docker Compose
Compose runs the whole stack from one file. The essentials:
compose.yamlis the canonical name; drop the top-levelversion:key — Compose v2 ignores it.depends_onwithcondition: service_healthy— a database that is running is not yet accepting connections; a healthcheck plus the condition removes the race.- Fail fast on missing secrets with
${DB_PASSWORD:?set DB_PASSWORD in .env}. - Named volumes for data (
db-data:/var/lib/mysql, Drupal’ssites/default/files) — bind mounts are for source code. - Dev vs prod by merging files:
compose.override.yamlloads automatically for development, production runsdocker compose -f compose.yaml -f compose.prod.yaml up -d. - Profiles for optional services (
profiles: ["search"]on Solr, started with--profile search).
docker compose up -d --build # (re)build and start in the background
docker compose ps # status and health
docker compose logs -f php # follow one service
docker compose exec php bash # shell in a running container
docker compose run --rm php composer install # one-off command
docker compose config # validate and show the merged config
docker compose stop # stop, keep containers and volumes
docker compose down # remove containers (named volumes kept)
docker compose down -v deletes named volumes — that is your database. Data on an anonymous volume (a VOLUME in the image with no name in Compose) is orphaned by a plain down too. When in doubt, stop, and dump the database first.
Docker Model Runner (docker model)
Docker Model Runner pulls AI models as OCI artifacts (Docker Hub ai/ namespace, any OCI registry, Hugging Face) and serves them through an OpenAI-compatible API — a free, keyless local backend for development.
docker model status # is the runner active?
docker model pull ai/smollm2 # fetch a model
docker model list # local models
docker model run ai/smollm2 "Hello" # one-shot prompt
docker model logs # runner logs
docker model rm ai/smollm2 # delete a local model
The API lives under /engines/v1 (/models, /chat/completions, /embeddings). From the host it is http://localhost:12434; from a container on Docker Desktop http://model-runner.docker.internal; on Docker Engine http://172.17.0.1:12434. Any OpenAI SDK works by pointing base_url at it — the API key is any non-empty placeholder.
In Compose, declare the model next to the services; Compose pulls it and injects its URL and name as environment variables (LLM_URL, LLM_MODEL):
services:
app:
image: my-app
models:
- llm
models:
llm:
model: ai/smollm2
context_size: 4096
The same endpoint works as an OpenAI-compatible provider for the Drupal AI module — local AI features without cloud keys or costs.
Everyday docker commands
# containers
docker ps -a # all containers, including stopped
docker logs -f --tail 100 <container> # follow the last 100 log lines
docker exec -it <container> sh # shell inside
docker inspect <container> # full config: mounts, networks, env
docker stats --no-stream # CPU / memory per container
docker cp <container>:/path ./local # copy a file out
# images
docker build -t app:dev . # build from the Dockerfile
docker image ls # local images
docker history app:dev # layers and their sizes
# networks and volumes
docker network ls
docker network inspect <network> # who is attached, which IPs
docker volume ls
# disk
docker system df # what takes the space
docker image prune # dangling images
docker builder prune # build cache
Read docker system df before you prune, and never run docker system prune --volumes or docker volume prune on a host with data you care about — they delete volumes not attached to a running container.
Troubleshooting
| Symptom | Fix |
|---|---|
| App fails with “connection refused” to the DB on start | Add a DB healthcheck and depends_on.condition: service_healthy |
port is already allocated | Another container or stack holds the host port — docker ps to find it, or change the ports: mapping |
| Containers can’t reach each other | Use the service name as hostname inside the Compose network, not localhost; check both are on the same network |
Changes to compose.yaml have no effect | docker compose up -d again (recreates changed services); check docker compose config |
| Permission denied on a bind mount | Align the container user: UID with the host, or fix ownership in the entrypoint |
| Every build reinstalls dependencies | Copy the manifest files and install before COPY . . |
| Disk full | docker system df, then prune images and build cache — not volumes |
| Database empty after a restart | It was on a volume removed by down -v (or an anonymous one) — restore from a dump |
Source
The Compose and Model Runner parts are real, installable Claude Code skills — docker-compose and docker-model in the docker-tools plugin
of the siva01c/claude-plugins
marketplace repository. This page summarises them and adds the Dockerfile and CLI practice around them; the linked skills are the source of truth for their parts.