[{"id":"dockerintermediate-001","courseId":"docker-intermediate","domain":"images-builds","topic":"Build cache invalidation","prompt":"A Dockerfile build checks its cache as it goes. Put these steps of the builder's cache check in the order the builder performs them.","hint":"Think about where the builder begins and what one mismatch does to everything after it.","explain":"The builder reuses cached layers only while each instruction still matches what was built before. A mismatch is not local: it affects every instruction that follows it.","source":"https://docs.docker.com/build/cache/invalidation/","interaction":{"type":"sort","items":[{"text":"Check whether the base image is already in the cache.","why":"The builder starts with the base image, so this is the first cache check."},{"text":"Compare each later instruction with the cached layers.","why":"After the base image, every following instruction is matched against the cached layers in turn."},{"text":"Invalidate the cache where no cached layer matches exactly.","why":"The first instruction with no exact match is where the cache stops being used."},{"text":"Generate new images for all remaining instructions.","why":"Once the cache is invalidated it is not used again, so the rest of the build is rebuilt."}]},"options":[],"answer":"o:abcd","explanation":"The builder checks the base image, then compares each instruction with the cached layers. The first instruction that does not match exactly invalidates the cache, and every later instruction is rebuilt.","concept":"The builder checks the base image, then compares each instruction with the cached layers. The first instruction that does not match exactly invalidates the cache, and every later instruction is rebuilt.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["One changed instruction rebuilds everything after it."]},{"id":"dockerintermediate-002","courseId":"docker-intermediate","domain":"images-builds","topic":"Multi-stage builds","prompt":"A Dockerfile has a stage 'FROM golang AS build' that runs 'go build -o /bin/hello', then a final stage 'FROM scratch' with 'COPY --from=build /bin/hello /bin/hello'. What does the final image contain?","hint":"Look at what the final stage starts from and what it copies in.","explain":"A Dockerfile can hold several FROM stages, and each one starts from its own base. Files move between stages only when a COPY --from names them.","source":"https://docs.docker.com/build/building/multi-stage/","interaction":{"type":"single"},"options":[{"id":"a","text":"The Go SDK and every file from the build stage","whyNot":"The build stage is left behind, so nothing in it reaches the final image unless it is copied across."},{"id":"b","text":"Only the binary copied in from the build stage, on top of scratch","why":"The final stage starts from an empty scratch base and receives just the copied binary; the Go SDK and intermediate files are not saved."},{"id":"c","text":"Every stage stacked together, since each FROM adds its layers","whyNot":"Earlier stages are not stacked into the final image; by default only the last stage is the image."},{"id":"d","text":"The build stage's files, since COPY --from copies the whole stage","whyNot":"COPY --from copies only the paths you name, not the whole stage."}],"answer":"b","explanation":"Each FROM starts a new stage. By default the last stage becomes the image, and earlier stages such as build tools are left out unless COPY --from brings specific files across.","concept":"Each FROM starts a new stage. By default the last stage becomes the image, and earlier stages such as build tools are left out unless COPY --from brings specific files across.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"FROM golang AS build\nRUN go build -o /bin/hello ./main.go\n\nFROM scratch\nCOPY --from=build /bin/hello /bin/hello","takeaways":["Copy only the artifacts you need into a minimal final stage."]},{"id":"dockerintermediate-003","courseId":"docker-intermediate","domain":"images-builds","topic":"ARG instruction","prompt":"A Dockerfile has these lines: USER ${username:-some_user}, then ARG username, then USER $username. The build runs with --build-arg username=what_user. Which user does the first USER line set?","hint":"Check which line the ARG is declared on, and what a reference above it can see.","explain":"An ARG variable takes effect only from the line where it is declared onward. A reference above that line sees no value, so whatever the reference itself specifies applies there.","source":"https://docs.docker.com/reference/dockerfile/#arg","interaction":{"type":"single"},"options":[{"id":"a","text":"what_user, the value passed with --build-arg","whyNot":"The ARG line comes after the first USER, so the value is not in scope yet at that line."},{"id":"b","text":"An empty string, because undefined variables always expand to nothing","whyNot":"That is true without a fallback, but ${username:-some_user} supplies a default when the variable has no value."},{"id":"c","text":"some_user, the fallback in the first USER line","why":"Before the ARG line, username has no value, so the :- default is used."},{"id":"d","text":"The build fails, because the variable is used before it is declared","whyNot":"Using a variable before its ARG line is not an error; the variable just has no value there."}],"answer":"c","explanation":"An ARG takes effect only from its declaration line onward. Earlier references see no value, so a ${var:-default} fallback applies there and the --build-arg value is not used.","concept":"An ARG takes effect only from its declaration line onward. Earlier references see no value, so a ${var:-default} fallback applies there and the --build-arg value is not used.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"FROM busybox\nUSER ${username:-some_user}\nARG username\nUSER $username","takeaways":["An ARG only applies from the line where it is declared onward."]},{"id":"dockerintermediate-004","courseId":"docker-intermediate","domain":"images-builds","topic":"ENV instruction","prompt":"In this Dockerfile, ARG CONT_IMG_VER is followed by ENV CONT_IMG_VER=v1.0.0. Built with --build-arg CONT_IMG_VER=v2.0.1, the RUN echo $CONT_IMG_VER line prints v2.0.1.","hint":"Consider which of the two declarations wins when both set the same name.","explain":"ARG values come from the docker build command, while ENV is written into the Dockerfile and saved in the image. When both name the same variable, the precedence between them is what matters.","source":"https://docs.docker.com/reference/dockerfile/#env","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The ENV line overrides the ARG of the same name, so RUN prints v1.0.0 even when --build-arg passes v2.0.1."},{"id":"b","text":"False","why":"An ENV instruction overrides an ARG with the same name, so the RUN line prints v1.0.0."}],"answer":"b","explanation":"An ENV instruction overrides an ARG of the same name, so a --build-arg value does not replace the ENV value in later RUN instructions.","concept":"An ENV instruction overrides an ARG of the same name, so a --build-arg value does not replace the ENV value in later RUN instructions.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["When ARG and ENV share a name, ENV wins."]},{"id":"dockerintermediate-005","courseId":"docker-intermediate","domain":"images-builds","topic":"ENTRYPOINT versus CMD","prompt":"This image ends with the two instructions below. Which TWO statements about running a container from it are true?","hint":"Think about which instruction names the program and which one holds replaceable defaults.","explain":"ENTRYPOINT sets the program a container runs, while CMD holds arguments that are easy to change at run time. Check how each one behaves when docker run is given its own arguments.","source":"https://docs.docker.com/reference/dockerfile/#entrypoint","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"Passing sh to docker run replaces ENTRYPOINT, so a shell starts instead of the server","whyNot":"Words after the image name are passed as arguments to ENTRYPOINT, not used as a new program, unless you override ENTRYPOINT with --entrypoint."},{"id":"b","text":"Arguments after the image name in docker run replace CMD, so /app/server receives the new arguments","why":"CMD is the default argument list, and anything given to docker run takes its place while ENTRYPOINT still runs."},{"id":"c","text":"The CMD line is ignored whenever an ENTRYPOINT is defined in the same Dockerfile","whyNot":"CMD still supplies default arguments to ENTRYPOINT; it is not dropped when ENTRYPOINT is present."},{"id":"d","text":"With no arguments given, the server runs with --port 8080 as its default arguments","why":"CMD supplies default arguments to the ENTRYPOINT program when docker run adds none."},{"id":"e","text":"Each instruction runs as a separate process, so the server and the CMD command start together","whyNot":"ENTRYPOINT and CMD form one command line; CMD is not started as a second process."},{"id":"f","text":"A container with an ENTRYPOINT cannot accept any arguments from docker run","whyNot":"Arguments given to docker run are appended to ENTRYPOINT, so the container still accepts arguments."}],"answer":"bd","explanation":"ENTRYPOINT is the program a container runs. CMD supplies its default arguments, and arguments passed to docker run replace CMD, not ENTRYPOINT.","concept":"ENTRYPOINT is the program a container runs. CMD supplies its default arguments, and arguments passed to docker run replace CMD, not ENTRYPOINT.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"ENTRYPOINT [\"/app/server\"]\nCMD [\"--port\", \"8080\"]","takeaways":["Put the program in ENTRYPOINT and replaceable defaults in CMD."]}]