Containers · Course contents
Machine not started
30 min·Intermediate

Build a small container image

Interpret a deliberately small Containerfile language into a root filesystem and launch metadata.

Jump to code and terminal ↓

Turn a specification into files

A builder interprets instructions and produces a root filesystem plus configuration. Our FROM names one predefined BusyBox base. COPY adds a regular context file, and RUN executes a build command through chroot.

Keep build-time and run-time state distinct

ENV records KEY=VALUE lines. WORKDIR creates an absolute image directory and records it. RUN uses the environment and current directory immediately. CMD records a shell command for a later runner; building must not execute it.

FROM minimal-rootfs
COPY hello /hello
ENV GREETING=hello
WORKDIR /app
RUN echo built > /built
CMD /hello

Your change

Finish the instruction dispatcher. The helpers validate COPY paths, install the base, and execute build commands. This intentionally limited format supports one FROM, regular-file COPY, shell-form RUN/CMD, one KEY=VALUE per ENV, and absolute WORKDIR; JSON syntax, quoting rules, multistage builds, and layer caching are outside this language.

Your goal

Implement COPY, RUN, ENV, WORKDIR, and CMD using the supplied filesystem helpers and a predefined FROM base.

What the tests observe

  • Two distinct real rootfs builds
  • Build-time environment and directory
  • Run metadata preserved
  • COPY context boundary

Need a nudge?

Hint 1

Use the supplied init_image, copy_file, and run_build helpers; finish the case branches.

Hint 2

ENV appends a validated KEY=VALUE line. WORKDIR creates the image directory and writes its absolute path to image/workdir.

Hint 3

CMD writes its shell command to image/cmd; do not execute it during the build. RUN calls run_build after earlier state changes.

What happens inside Linux

You now own a small image format: filesystem bytes plus execution metadata. A production builder adds content-addressed layers, reproducibility, cache keys, isolation for RUN, and a much larger instruction grammar; this builder makes those boundaries explicit.

Optional account sync. Exercises work without an account.

sh/work/builder.shLoading local work…
Restoring your workspace…
⌘ / Ctrl ↵
TerminalRISC-V 64 · root · /work

Your Linux machine is ready to start.

Boot a disposable environment in this browser. You’ll get a real root shell, with no remote server or account required.

Filesystem checks

Observed inside Linux

Run tests to inspect the root filesystem and the view from inside chroot. Each check reports the behavior your program produced.