Docker Exec and Logs

Execute commands and view logs

Execute Commands

docker exec container command # run command in container
docker exec -it container bash # interactive bash shell
docker exec -it container sh # interactive sh shell
docker exec -d container command # detached execution

View Logs

docker logs container # view container logs
docker logs -f container # follow logs (tail -f)
docker logs --tail 100 container # last 100 lines
docker logs --since 5m container # logs from last 5 minutes
docker logs -t container # show timestamps

Attach to Container

docker attach container # attach to running container

Copy Files

docker cp container:/path/file . # copy from container
docker cp file container:/path/ # copy to container

Container Stats

docker stats # live resource usage stats
docker stats container # stats for specific container
docker top container # show running processes

Inspect Container

docker inspect container # detailed container info
docker port container # show port mappings