csot/contest

Task 10 — Container Doctor

How to evaluate

csot submit ./solutions -w week-02 -t 10

Submit as: 10.sh Write a one-shot diagnostics script your team can run during an incident. Given a container name or id, print a JSON summary of its state.

Output

Valid JSON on stdout, for example:

{
  "name": "app-1",
  "state": "running",
  "health": "healthy",
  "ip": "172.18.0.3",
  "ports": ["0.0.0.0:32768->8000/tcp"],
  "user": "10001"
}
  • state, health, ip, user come from docker inspect.
  • ports from docker inspect/docker port (any form that includes the mapping is accepted).
  • If the container does not exist, exit with code 2.

What the grader checks

  • Valid JSON (4 pts)
  • Correct state, health, ip, ports, user for a known container (9 pts)
  • Exit code 2 when the container is missing (1 pt)

Hints

  • docker inspect -f '{{.State.Status}}' <c>, {{.State.Health.Status}}, {{.Config.User}}, {{.NetworkSettings.IPAddress}} (or per-network).
  • jq -n builds JSON safely from shell variables.

Points: 14

Other tasks