Looking Inside: logs & exec
Your Two Debugging Superpowers
docker logs shows everything the main process wrote to stdout/stderr - in containers, apps log to the console, not to files:
$ docker logs web # everything so far
$ docker logs -f web # follow live (like tail -f)
$ docker logs --tail 50 web # last 50 lines
docker exec runs an extra command inside a running container:
$ docker exec web ls /usr/share/nginx/html # one-off command
$ docker exec -it web sh # interactive shell
Scenario: Production serves the wrong page. Instead of redeploying, youdocker exec -it web sh, look at the actual files nginx is serving, and spot the staleindex.htmlin seconds. Then you fix the image so the next deploy is correct.
Warning: Changes made viaexeclive in the container's writable layer - they vanish when the container is removed and they're not in the image.execis for diagnosis and emergency hotfixes, never for permanent configuration.
Housekeeping:
$ docker stop web # graceful (SIGTERM, then SIGKILL after 10s)
$ docker rm web # remove a stopped container
$ docker rm -f web # stop + remove in one step