Dokcer Interview Questions: ============================= ๐Ÿ”ฅ Advanced Practical Docker Interview Questions ๐Ÿงฑ 1. Docker Architecture & Internals Q: Explain how Docker works internally when you run docker run nginx. ๐Ÿ‘‰ Expected: Docker CLI → Docker Daemon → containerd → runc Image pull from registry Creation of container using namespaces & cgroups ๐Ÿณ 2. Write a Dockerfile (Real Scenario) Q: Create a Dockerfile for a Node.js app. FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm install COPY . . EXPOSE 3000 CMD ["npm", "start"] ๐Ÿ‘‰ Follow-up: How to reduce image size? Why use alpine? ๐Ÿ“ฆ 3. Multi-Stage Build (Very Important) Q: Optimize this Dockerfile for production. # Build stage FROM node:18 as builder WORKDIR /app COPY . . RUN npm install && npm run build # Production stage FROM nginx:alpine COPY --from=builder /app/build /usr/share/nginx/html ๐Ÿ‘‰ Key concept: Reduce final image size Separate build & runtime ๐Ÿ” 4. Secrets Handling Q: How do you pass secrets (DB password) securely? ๐Ÿ‘‰ Expected answers: Docker secrets (Swarm) Environment variables (not best for sensitive) Use AWS Secrets Manager / Vault ๐ŸŒ 5. Networking (Practical) Q: Two containers need to communicate. How? docker network create mynet docker run -d --name app --network mynet myapp docker run -d --name db --network mynet mysql ๐Ÿ‘‰ Follow-up: Default network vs bridge vs host vs overlay ๐Ÿ“ 6. Volumes & Persistence Q: My container data is lost after restart. Fix it. docker volume create mydata docker run -v mydata:/var/lib/mysql mysql ๐Ÿ‘‰ Concept: Volumes vs bind mounts ⚙️ 7. Debugging Container Issues Q: Container is crashing. What will you do? ๐Ÿ‘‰ Commands: docker logs docker inspect docker exec -it sh docker top ๐Ÿš€ 8. Performance Optimization Q: How to reduce Docker image size? ๐Ÿ‘‰ Expected: Use alpine images Multi-stage builds Remove unnecessary packages Use .dockerignore ๐Ÿ”„ 9. Container Lifecycle Q: Difference between: CMD vs ENTRYPOINT ๐Ÿ‘‰ Example: ENTRYPOINT ["nginx"] CMD ["-g", "daemon off;"] ๐Ÿ”’ 10. Security (Very Important) Q: How to secure Docker containers? ๐Ÿ‘‰ Expected: Run as non-root user Use minimal base images Scan images (Trivy) Limit capabilities ๐Ÿ“Š 11. Resource Limits Q: Limit CPU and memory of a container. docker run -d --memory="512m" --cpus="1.0" nginx ๐Ÿ” 12. Restart Policies docker run -d --restart=always nginx ๐Ÿ‘‰ Types: no on-failure always unless-stopped ๐Ÿงช 13. Health Checks HEALTHCHECK CMD curl --fail http://localhost || exit 1 ๐Ÿ“ฆ 14. Image Management Q: Difference between: docker save vs docker export ๐Ÿ‘‰ Expected: save → image export → container filesystem ☁️ 15. Registry & CI/CD Q: How do you push image to Docker Hub / ECR? docker login docker tag myapp username/myapp:latest docker push username/myapp:latest ๐Ÿ”ง 16. Docker Compose (Real Use) version: '3' services: app: build: . ports: - "3000:3000" db: image: mysql environment: MYSQL_ROOT_PASSWORD: root ๐Ÿ‘‰ Follow-up: How to scale services? docker-compose up --scale app=3 ⚠️ 17. Troubleshooting Scenario Q: Container works locally but not in server. Why? ๐Ÿ‘‰ Possible reasons: Port not exposed Firewall issue Env variables missing Different architecture ๐Ÿง  18. Real DevOps Scenario Q: How do you deploy Docker in production? ๐Ÿ‘‰ Expected: Use Kubernetes / ECS CI/CD pipeline (GitHub Actions, Jenkins) Monitoring (Prometheus, Grafana) ๐ŸŽฏ 19. Logging Strategy Q: Where logs are stored? /var/lib/docker/containers//-json.log ๐Ÿงฉ 20. Difference Questions (Very Common) Container vs VM Image vs Container Volume vs Bind Mount CMD vs ENTRYPOINT

Comments

Popular posts from this blog

Linux interview questions

Aws Interview Questions