Run one-off development tasks
Use compose run when you want a separate short-lived container using a service definition. The supplied command takes the place of the usual service command; the image entrypoint still applies. In the example the ordinary worker sleeps, while a one-off container prints a report and exits. --rm removes that temporary container, --no-deps prevents automatic dependency startup, and -T avoids allocating a terminal. run does not publish the configured service ports by default. This is useful for migrations or tooling, but real data changes require review and backups. Shared mounts can persist changes even after the one-off container is removed.
Read the development model
services: worker: image: busybox:1.37 pull_policy: never user: 10001:10001 command: - sleep - '300' network_mode: noneManual lab
Manual lab only, not browser execution. Use a fresh approved disposable Linux VM with external egress blocked and a local Docker context. Check docker context show, docker version and docker compose version; verify the exact options and fields. Preload and verify a native-platform BusyBox 1.37 image digest, entrypoint and required applets; the tag is mutable. For builds verify a local Buildx docker driver using the reviewed base, with network blocked. Check all bm-v14 project and image names are unused and inherited Compose settings do not interfere. Use only a disposable copy of the supplied synthetic files; confirm UID 10001 can read source files. No public ports, external pulls/pushes, real secrets, broad host mounts or privileged containers. Run each line separately, stop on unexpected failures, clean only the lab and dispose of the VM. All results are predictions. Before Engine requests, verify the effective endpoint including DOCKER_HOST and DOCKER_CONTEXT; a project name does not select the daemon. Review inherited COMPOSE_ENV_FILES, COMPOSE_DISABLE_ENV_FILE, profile and project settings. Use a clean shell and the exact fixture directory. Inspect only synthetic config, logs and files. If a build is required, verify the effective builder can resolve the approved local base without egress; stop if build fails, never reuse a stale tag.
Open lab-fixtures/docker-compose-development/04-one-off-tasks/ in the extracted archive and run from a disposable copy of that folder.
docker compose -f compose.yaml -p bm-v14-one-off-tasks config --quietdocker compose -f compose.yaml -p bm-v14-one-off-tasks up -d --no-build --pull neverdocker compose -f compose.yaml -p bm-v14-one-off-tasks run --rm --no-deps -T --pull never worker printf "report-v14\n"docker compose -f compose.yaml -p bm-v14-one-off-tasks ps -aThe one-off command should print report-v14 while the ordinary worker remains running. The temporary container should disappear after exit. Record the ordinary worker ID before and after, plus the one-off exit status. Check project container inventory (including stopped containers) after completion, rather than assuming --rm worked.
Clean only the named lab projects; no global prune or force removal. Retain the reviewed base image. A failed cleanup requires VM disposal and review.
docker compose -f compose.yaml -p bm-v14-one-off-tasks downdocker compose -f compose.yaml -p bm-v14-one-off-tasks ps -aCommon mistake
--rm does not undo changes made to a shared database or volume. Keep this lab free of persistent data.
Manual practice
Choose run or exec for a task that needs its own container, and explain the resource lifetime.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Run one-off development tasks — Knowledge check
Reason about development workflows and their effects.
What does run create?
What does --rm remove?
Why use --no-deps here?