Capture logs from crashing container Start Docker Container Locally
docker exec -it docker ps -aq | head -1 tail -f /app/logs/USER-user-service.txt
- don't quote command
Look at dead container's filesystems docker inspect | grep volume Locally on Mac, you won't be able to access /var/lib/docker. You need to use screens command:
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty cd /var/lib/docker/volumes ls -ltr | tail Use ctrl-a d to detach, 'screen -S -X quit' to stop screen process
BusyBox containers exit immediately because they don't have a long-running process by default.
Problem: Container exits even with -d flag
docker run -p 8080:8080 -d --name box-1 busybox # This exits immediatelySolutions:
# Keep container running with sleep
docker run -p 8080:8080 -d --name box-1 busybox sleep infinity
# Interactive mode with pseudo-TTY
docker run -p 8080:8080 -d -it --name box-2 busybox
# Keep running with tail command
docker run -p 8080:8080 -d --name box-3 busybox tail -f /dev/nullExecute commands inside running containers:
# Interactive shell session
docker exec -it container_name /bin/sh
# For containers with bash
docker exec -it container_name /bin/bash
# Run single command
docker exec container_name ls -la
# Run command and see output
docker exec container_name ps auxFlags explained:
-i(interactive): Keep STDIN open-t(tty): Allocate a pseudo-TTY-ittogether: Interactive terminal session
TO delete the exited containers docker rm $(docker ps -aq --filter "name=box-1" --filter "status=exited")