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,usercome fromdocker inspect.portsfromdocker 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,userfor a known container (9 pts) - Exit code
2when the container is missing (1 pt)
Hints
docker inspect -f '{{.State.Status}}' <c>,{{.State.Health.Status}},{{.Config.User}},{{.NetworkSettings.IPAddress}}(or per-network).jq -nbuilds JSON safely from shell variables.