Understanding the Problem
Container exits immediately after start (status: Exited).
View Logs
docker logs container_name
docker logs container_id
docker logs --tail 50 container_name
docker logs -f container_name
Common Causes and Fixes
1. Command Finishes Immediately
docker run ubuntu echo "hello"
docker run -d ubuntu sleep infinity
docker run -d nginx
2. Missing Interactive Mode
docker run -it ubuntu bash
3. Port Conflict
Check logs for port allocation errors.
4. Missing Environment Variables
docker run -e "VAR=value" image_name
5. Volume Mount Issues
ls -la /host/path
docker run -v /absolute/host/path:/container/path image
Debug Mode
docker run -it --entrypoint /bin/bash image_name
Dockerfile Fix
CMD ["nginx", "-g", "daemon off;"]
Exit Code Check
docker inspect container_name --format='{{.State.ExitCode}}'