DOCKER · Inspection · 8 min

Label a container and find it precisely

Use metadata filters instead of relying on a visual scan.

Not completed

Your task

Run the image as the named container with training.topic=inspection. Save that label value into label.txt and find the container using a label filter.

What you’re aiming for

  • label.txt contains inspection.
  • The named container carries the requested label.

1. Prepare your practice folder

Use a running Docker engine in Linux container mode. The setup commands below use a Bash-compatible shell: Git Bash on Windows, or Bash on Linux/macOS.

Create a new, empty folder for this exercise. If that name already exists, choose another new name. Continue only after you’re inside the new folder.

NEW PRACTICE FOLDER
mkdir opsrung-docker-label-and-find && cd opsrung-docker-label-and-find

Run these setup commands in that folder:

SETUP — RUN ONCE
cat > Dockerfile <<'DOCKERFILE'
FROM alpine:3.22
USER 65534:65534
CMD ["echo","Practice ready"]
DOCKERFILE
docker build -t opsrung-label-and-find:practice .

Docker may download the official Alpine image and, for the web task, its HTTP package. If an example container name already exists, use a different name consistently. If port 8088 is occupied, choose another free local port.

2. Try the task

Work toward the goal above. Start by inspecting the files or resources, then use a hint if you need one.

Hint 1

--label attaches metadata when a container is created.

Hint 2

docker ps -a --filter includes stopped containers.

Hint 3

Inspect the label map and write just its training.topic value to a file.

3. Review your result

Use these commands to look at your result and compare it with the goals. The website does not run or verify them.

REVIEW IN YOUR TERMINAL
cat label.txt
docker ps -a --filter label=training.topic=inspection --format "{{.Names}}"

What you should see

  • label.txt contains inspection.
  • The named container carries the requested label.

If your result differs: Compare the actual output with each goal. Keep your work inside this exercise’s folder and use only its named resources.

Compare with one possible solution
ONE POSSIBLE SOLUTION
docker run --name opsrung-label-and-find --network none --read-only --cap-drop ALL --security-opt no-new-privileges --label training.topic=inspection opsrung-label-and-find:practice
docker ps -a --filter label=training.topic=inspection --format "{{.Names}}"
docker inspect opsrung-label-and-find --format '{{index .Config.Labels "training.topic"}}' > label.txt

Other approaches are fine if you reach the same goal. Opening this solution does not mark the exercise complete.

Clean up this exercise

Only remove the example resources you created. Volume cleanup deletes that exercise’s saved sample data. Keep anything you need.

OPTIONAL CLEANUP
docker stop opsrung-label-and-find
docker rm opsrung-label-and-find
docker image rm opsrung-label-and-find:practice

Finished this exercise?

You decide when you’re done. Your choice is saved in this browser, and you can change it later.