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

CommandWhat it does
docker exec -it <c> shOpen a shell in a running container
docker exec <c> envInspect 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 ./outCopy 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.

Perguntas frequentes

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