Docker Exec and Logs
Get a shell inside containers and read their logs effectively.
- docker exec
- docker logs
- docker cp
- follow logs
- container shell
Docker Exec and Logs
Get a shell inside containers and read their logs effectively.
Commands
| Command | What it does |
|---|---|
docker exec -it <c> sh | Open a shell in a running container |
docker exec <c> env | Inspect a container's environment |
docker logs -f --tail 100 <c> | Follow the last 100 log lines |
docker logs --since 10m <c> | Logs from the last 10 minutes |
docker cp <c>:/app/out ./out | Copy files out of a container |
Example
docker exec -it api sh
docker logs -f --tail 100 api
docker cp api:/app/report.json ./report.json
FAQ
sh vs bash in exec?
Alpine-based images ship only sh; debian-based images usually have bash. Try sh first.
Logs show nothing — why?
The app may log to files instead of stdout; exec in and check, or configure a json-file log driver.
Preguntas frecuentes
sh vs bash in exec?
Alpine-based images ship only sh; debian-based images usually have bash. Try sh first.
Logs show nothing — why?
The app may log to files instead of stdout; exec in and check, or configure a json-file log driver.
Docker
Docker Install and Setup
Verify the Docker engine, configure context, and check versions.
Docker Images
Pull, list, tag, inspect, and remove images confidently.
Docker Containers
Run, list, stop, and clean up containers in daily work.
Docker Run Options
The flags that matter: detach, ports, env, volumes, limits.