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
HSBC Bank: Name : Srikanth Patil Mobile : 9513273723 Email Id : Srikanth.patil@hsbc.co.in How to check payslips : Go to the portal: here we can see the link: https://infinite.greyhr.com/login.do Quick links : GreytHR ---------------------------------------------------- Medical and group insurance : Contact : shafi +91 -7022557573 email address: mediclaimhelpdesk@infinite.com For any escalation write to : MYHR@infinite.com Quicklink -BIZX: https://bizx.inifinite.com --------------------------------------------------------- Axis Bank : Name : Ragini sharma Mobile Number: 8088982659 mail address: Ragini.sharma@axisbank.com --------------------------------------------------------- Name : Archishman Mobile number: 7678068570 mail address: Archishman.Deb@axisbank.com -------------------------------------------------------- Hdfc Bank : Name : Pavan katariya Mobile Number: 9986349366 Mail address: pavan.katariya@hdfcbank.com ----------------...
Comments
Post a Comment