Docker lifecycle lab: run a small batch job
Quick answer
Combine the lifecycle commands to prepare a small job, run it, check its output and status, rerun it, and remove only its own container. The goal is to predict the state at each stage rather than memorize a command list.
Before you run commands
Use an approved disposable Linux-container Docker lab. Confirm the effective context and permissions; use a reviewed, locally preloaded busybox:1.37 image whose digest/platform the lab owner has recorded. This tag is mutable. Do not download an image automatically; --pull=never requires it locally. The new containers use --network none, with no host mounts or published ports; the CLI still connects to the selected engine. Verify the approved image tag still resolves to the recorded image before creating containers. Check docker ps -a for all names used below. If any is occupied, choose fresh names consistently. Run commands one at a time and stop on any unexpected failure; never act on resources you did not create. Expected results are predictions, not measured execution.
How it works
Your job prints two lines and exits successfully. Start with an unused name and no mounts. First prepare without running. Observe created; launch and wait; inspect exited and exit code zero. Run again using the same identity and inspect again. Clean up only after checking results. A pause suspends running processes without ending them; unpause resumes them. This is different from stop/start, which ends and relaunches the program. A short batch job may finish before pause is possible, so the optional pause demonstration uses a bounded sleep.
docker create --pull=never --network none --name bm02-job busybox:1.37 sh -c 'echo report; echo complete'docker inspect --format '{{.State.Status}}' bm02-jobdocker start -a bm02-jobdocker wait bm02-jobdocker inspect --format '{{.Id}} {{.State.Status}}' bm02-jobdocker start -a bm02-jobdocker inspect --format '{{.Id}} {{.State.Status}}' bm02-jobdocker rm bm02-jobExpect created, two report messages, exit code 0, then exited on both final inspections with identical IDs.
docker run -d --init --pull=never --network none --name bm02-pause busybox:1.37 sleep 120docker pause bm02-pausedocker inspect --format '{{.State.Status}}' bm02-pausedocker unpause bm02-pausedocker stop -t 2 bm02-pausedocker rm bm02-pauseOn a compatible Linux engine, expect paused while suspended. Run promptly and always unpause before cleanup. Skip if unsupported. If the sleep ends before pause, skip the optional demonstration or start a fresh owned lab container. If pause succeeds but a later step fails, ask the lab owner to confirm the state and safely unpause before cleanup.
Common mistake
If preparation fails, do not continue against a name that may belong to someone else. Verify the active lab context and ownership, and check each command outcome. Never use a real service to experiment with pause or removal.
Try it yourself
Without looking at the reference workflow, create a job that prints inventory and exits with 0. Record expected and actual states, whether the ID changes on rerun, and whether the named object is absent after removal. If no lab is available, write predictions only.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Docker lifecycle lab: run a small batch job — knowledge check
Apply the lifecycle concepts and interpret the lab behavior.
Which sequence prepares a job, runs it, verifies completion and cleans it up?
What does pause do to a running Linux container?
A create command fails because its name exists. What should you do?