Docker Logs and Inspect
docker logs shows what a container printed, docker inspect shows how it is set up, and docker stats shows what it uses right now. The three commands answer three questions.
Count the requests in the logs
This command counts the page requests nginx logged.
docker logs g3-web | grep -c "GET /"Pick one inspect field
This command shows the container name and its running status.
docker inspect --format "{{.Name}} {{.State.Status}}" g3-webExample
docker run -d --name g3-web nginx:1.27-alpine >/dev/null
curl -s http://localhost:8081/ -o /dev/null
docker logs g3-web | grep -c "GET /"
docker inspect --format "{{.Name}} {{.State.Status}}" g3-webKey points
- Use docker logs to read a container's output after the fact.
- Use docker logs -f to follow new output as it arrives.
- Use docker inspect to see the container's full setup as structured data.
- Use docker inspect --format to pick one field out of that data.
- Use docker stats --no-stream for one snapshot of CPU and memory use.
In this example, Docker starts nginx and curl asks it for a page. docker logs counts the one request nginx wrote. docker inspect shows the container name and its running status. Logs answer what happened, and inspect answers how it stands.
Note
Logs show the past. Stats show the present. Inspect shows the setup.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
Which command shows what a container printed?