{ "id": "docker-build-image", "title": "Write a Real Dockerfile and Build a Real Image", "category": "Containers", "isolation_type": "shared_namespace", "difficulty": "Medium", "type": "task", "weight": 6, "description": "## Write a Real Dockerfile and Build a Real Image\n\nA file `/srv/build-lab/greeting.txt` already exists, containing a message.\n\n**Your task:**\n\n1. Write a `Dockerfile` at `/srv/build-lab/Dockerfile` that:\n - Starts `FROM alpine:3.19`\n - Sets the working directory to `/app`\n - Copies `greeting.txt` into the image\n - Runs `cat greeting.txt` as its default command\n2. Build it, tagged `rootnode-build-lab:1`\n3. Run a container from YOUR image and confirm it prints the real content of `greeting.txt`", "hints": [ { "title": "The Dockerfile", "body": "Each instruction builds one layer: FROM sets the base, WORKDIR sets the working directory for everything after it, COPY brings a file from the build context into the image, CMD sets the default command run when a container starts.", "command": "cat < /srv/build-lab/Dockerfile\nFROM alpine:3.19\nWORKDIR /app\nCOPY greeting.txt .\nCMD cat greeting.txt\nEOF" }, { "title": "Building and running", "body": "`docker build -t ` builds using the Dockerfile found in that directory. `docker run --rm ` runs it once and cleans up automatically afterward.", "command": "cd /srv/build-lab && docker build -t rootnode-build-lab:1 .\ndocker run --rm rootnode-build-lab:1" } ], "setup_commands": [ { "command": "rm -rf /srv/build-lab && mkdir -p /srv/build-lab" }, { "command": "echo 'Hello from my custom image' > /srv/build-lab/greeting.txt" }, { "command": "docker pull alpine:3.19" } ], "validation": { "commands": [ { "description": "the image was actually built with the expected tag", "command": "docker image inspect rootnode-build-lab:1 --format '{{.RepoTags}}' 2>/dev/null", "expected_output": "rootnode-build-lab:1", "match": "contains" }, { "description": "a container from the student's own image produces the real file content", "command": "docker run --rm rootnode-build-lab:1 2>/dev/null", "expected_output": "Hello from my custom image", "match": "exact" } ] }, "default_namespace": "default", "teardown_commands": [ { "command": "docker rmi rootnode-build-lab:1 2>/dev/null; rm -rf /srv/build-lab" } ] }