Quiz Entry - updated: 2026.11.10
What does this Dockerfile do, and what ends up in /codes/output.txt?
FROM alpine:latest
LABEL Creator="HSLU"
RUN apk update && apk add curl bash
RUN mkdir /codes
RUN curl -o - https://jsonplaceholder.typicode.com/todos/1 | grep title > /codes/output.txt
ENV APACHE_RUN_USER="www-data"
ENV APACHE_RUN_GROUP="www-data"
ENV APACHE_LOG_DIR="/var/log/apache2"
CMD ["/bin/bash"]
It builds an Alpine image with curl and bash, saves one line of a JSON response at build time, sets three Apache environment variables and opens a bash shell by default. The file contains "title": "delectus aut autem",.
Line by line:
FROM alpine:latest: start from the minimal Alpine Linux image.LABEL Creator="HSLU": a metadata key/value, visible withdocker image inspect.RUN apk update && apk add curl bash: refresh the package index and install curl and bash in one layer (Alpine'sapkinstead ofapt-get).RUN mkdir /codes: create a folder inside the image.RUN curl … | grep title > /codes/output.txt: fetch a demo JSON object, pipe (|) the output togrep, keep only the line containingtitle, and write it to a file. This runs at build time, so the file is frozen into the image.- Three
ENVlines: environment variables an Apache server would read. They prepare for the next step of the lab, which addsapache2. CMD ["/bin/bash"]: if no command is given, a container starts bash.
The test API returns {"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false} pretty-printed one field per line, so output.txt holds "title": "delectus aut autem",.
From the host, ls /codes finds nothing, since the folder exists only inside the container's filesystem. docker container exec -it alpinecontainermitenv bash opens a shell inside, where ls /codes and echo $APACHE_RUN_USER (www-data) confirm the build worked.
Go deeper:
JSONPlaceholder: /todos/1 — the demo JSON the build step fetches.
Docker Docs: Dockerfile reference, LABEL — image metadata and how to read it back.