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
Linux interview Questions :
1).How to recover accidently deleted /etc/fstab into linux os ? anyone deleted this /etc/fstab .after this we can' boot ur os. boot into recovery mode . then go to the linux terminal page . here we have to execute the blkid command here it will list out the avilble partions and attached filesystems . if your deleting the /etc/fatab.that time root parttion won't be work now we can mount the root parttion in rw mode mount -t ext4 -0 rw,remount dev/sda1 / 2).VMSTAT command into linux ? 3).iostat and dstat command into linux os ? 4).LInux free command into linux os ? in this way we can check it our the memeory usage and swap memeory as well. then it will display out the , used,space avilble ,total ,buffer/catche abd shared what is free space we can execute the command like as the, free -b command : we will get the particular output for the bits so if you want to getto int the outpit in kilobytes : so we can execut ethe comamnd like as the, free -k free -g: it will sh...
Comments
Post a Comment