# Containers की जाँच और Debugging — Docker Fundamentals: Images, Containers और Compose

Source: https://www.geekswithgeeks.com/hi/docker/docker-debugging

> docker logs, exec, inspect और stats से चलते containers debug करें, और container रुकने पर exit codes पढ़ें।

## Logs और exec

`logs` output दिखाता है, `exec` चलते container में shell खोलता है और `inspect` पूरी configuration दिखाता है।

```bash
docker logs -f --tail 100 web
docker exec -it web sh
docker inspect web | head -40
docker stats --no-stream
```

## यह क्यों रुका?

Container तब रुकता है जब उसका मुख्य process exit हो जाए। Exit code और आखिरी logs जाँचें।

```bash
docker ps -a
docker inspect -f "{{.State.ExitCode}}" web   # 0 = clean, 137 = killed/OOM, 1 = app error
docker logs web
```

अपने Dockerfile या Compose service में `HEALTHCHECK` जोड़ें ताकि Docker container को unhealthy चिह्नित कर सके और orchestrators उसे restart कर सकें।

त्वरित जाँच

**Quiz:** कौन-सा command चलते container में shell खोलता है?

- [x] docker exec -it web sh
- [ ] docker build -t web .
- [ ] docker pull web
- [ ] docker rm web

*Answer:* docker exec -it web sh. exec मौजूदा container के भीतर command चलाता है।
