Scenario Based Docker Interview Questions and Answers
1. Container is exiting immediately. What will you check?
Check container logs using docker logs and verify CMD or ENTRYPOINT configuration.
2. Docker image is too large. How do you reduce it?
Use multi-stage builds, slim base images and remove unnecessary packages.
3. Container cannot access the internet.
Check network settings, DNS configuration and firewall rules.
4. Application works locally but not inside container.
Check environment variables, exposed ports and dependencies.
5. Docker build is very slow.
Use layer caching, optimize Dockerfile order and reduce context size.
6. Container cannot connect to database.
Verify DB host, network, credentials and service name.
7. Logs are not visible.
Check logging driver, STDOUT logging and volume mounts.
8. Image pull fails from private registry.
Login to registry, check credentials and network access.
9. Container uses too much memory.
Set memory limits and optimize application.
10. Port mapping not working.
Verify container port, host port mapping and firewall.
11. Container restarts repeatedly.
Check restart policy and application crash logs.
12. Docker volume not persisting data.
Verify volume mount path and container permissions.
13. Build fails due to permission denied.
Run proper user permissions and avoid root where possible.
14. How do you secure Docker images?
Scan images, use minimal base image and avoid secrets in image.
15. Container cannot resolve hostname.
Check Docker DNS and network mode.
16. Too many unused images and containers.
Use docker system prune regularly.
17. Docker daemon not starting.
Check service logs, disk space and config file.
18. How do you handle environment-specific configs?
Use environment variables or external config files.
19. Multi-container app not communicating.
Use Docker network or Docker Compose service names.
20. Docker Compose file not working.
Validate syntax and service definitions.
21. Container runs as root. Is it safe?
No, use non-root user for security.
22. Image vulnerability found.
Rebuild image with patched base image.
23. Docker build context is huge.
Use .dockerignore to exclude files.
24. Container time is different from host.
Sync time using host settings or timezones.
25. Docker container stops unexpectedly.
Check logs, signals and resource limits.
26. Application needs SSL certificates.
Mount certs as volume and avoid baking into image.
27. How do you handle rolling updates?
Use orchestrator like Kubernetes or Swarm.
28. Docker container cannot write to disk.
Check file permissions and mounted volume path.
29. Registry storage is full.
Delete old images and enable garbage collection.
30. How do you monitor Docker containers?
Use Docker stats, Prometheus or monitoring tools.
Source: sureshtechlabs.com