Build and run your first custom Docker image
Read the recipe
FROM busybox:1.37WORKDIR /appCOPY title.txt ./title.txtRUN printf "status: ready\n" > status.txtCMD ["cat", "title.txt", "status.txt"]FROM brings the tools, WORKDIR chooses a directory, COPY packages the title, RUN prepares a status file, and CMD describes the default runtime action. The build command creates an image under a local tag. The --load option imports the single-platform build result into the local image store. No registry push is involved. The run command uses that image to create a temporary container. Record the newly built image ID before running it. An existing tag or an incomplete build is not sufficient evidence that the new recipe succeeded.
Try it in a local lab
Manual lab only. Use an approved disposable offline Linux VM with a local Docker Engine and a modern local Buildx builder using the docker driver. Check docker context show, docker version, docker buildx version and docker buildx ls before building. Verify the selected context and builder are local, and that reviewed busybox:1.37 is available to the builder and image store. Verify the base has no configured entrypoint and provides the utilities used in this recipe. Record its actual platform and digest; replace the tag with the reviewed digest for repeatability. No network egress is allowed in the VM: --network none limits RUN instructions, not all builder traffic. Do not enable network access if resolution fails. Check that the example image tag is unused and keep all data synthetic. In a dedicated lab shell, enter the indicated fixture directory and execute each command in order; stop on any unexpected failure. The fixture files are included in the archive or can be recreated from the snippets. Expected results are predictions, not tested outputs. Before contacting any Engine, resolve DOCKER_HOST, DOCKER_CONTEXT and CLI context overrides; also check BUILDX_BUILDER and any builder override. Confirm that the actual builder used by docker build is the approved local docker driver. Review the base configuration for inherited triggers, volumes, health checks, user, shell and required applets; stop if assumptions differ. Make a private working copy containing only the supplied synthetic files. An approved digest may require registry metadata resolution even when layers are present locally; if the offline builder cannot resolve it, stop and record the limitation. Record the actual base image ID, platform, builder version and output image ID; never substitute an unknown digest. Do not retry by enabling egress. Apply owner-approved time and resource budgets and retire the VM if cleanup is uncertain.
From the extracted archive root, open lab-fixtures/dockerfile-fundamentals/08-first-image/. Save the Dockerfile exactly as shown. The following additional files, if any, belong beside it.
docker build --load --network none -t bm-v07-first-image:lab .docker run --rm --pull=never --network none bm-v07-first-image:labdocker image inspect --format '{{.Config.WorkingDir}} {{json .Config.Cmd}}' bm-v07-first-image:labdocker run --rm --pull=never --network none bm-v07-first-image:labExpect two output lines: ByteMind report and status: ready. Inspect should show /app and the command array. Running a second time creates another container with the same starting contents.
After all commands finish, check that the tag identifies only your lab image and no container depends on it. Remove the tag without forcing deletion. Build cache may remain until the disposable VM is retired. Record output and exit status before removing the exact lab tag. Recheck the tag against the recorded output image ID; a tag may have been reassigned.
Common mistake
If the build fails, stop rather than running a previously tagged image by accident. If a container cannot find title.txt, check context, COPY source and WORKDIR before changing permissions. Removing a container does not remove its image; image cleanup is separate.
Manual practice
Make a separate copy of this fixture, replace the title with Weekly report, and choose a new unused local tag. Predict both lines and verify them in an approved lab. Remove only your new image after confirming no container needs it.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Build and run your first custom Docker image — Knowledge check
Apply the lesson concepts to a new build or container scenario.
Which build flag loads the single-platform result into the local image store?
Why does the report have two lines?
What should you do if the build fails?