Docker Interview Questions
Finally!! ๐
You have completed โ the Docker hands-on sessions, and I hope you have learned something valuable from it. ๐
Docker being a crucial topic for DevOps Engineer interviews, especially for freshers. Here are some essential questions to help you prepare and ace your Docker interviews:
Difference between an Image, Container, and Engine:
Image: A read-only template with instructions to create a Docker container.
Container: A running instance of a Docker image.
Engine: The runtime that manages containers on a host system.
Difference between the Docker command COPY vs ADD:
COPY: Copies files/directories to the container without any additional functionality.
ADD: Similar to COPY but also supports fetching remote URLs and extracting archives.
Difference between the Docker command CMD vs RUN:
CMD: Sets the default command to run when the container starts.
RUN: Executes a command during the build process and creates a layer in the image.
How will you reduce the size of a Docker image?
- Use multi-stage builds, minimize the number of layers, remove unnecessary files, and use
.dockerignore
.
- Use multi-stage builds, minimize the number of layers, remove unnecessary files, and use
Why and when to use Docker?
- Use Docker for consistent environments, easy deployment, scalability, and isolation of applications for their easy shipment.
Explain the Docker components and how they interact with each other.
Components: Docker Engine, Docker Images, Docker Containers, Docker Daemon, Docker CLI, and Docker Compose.
Interaction: The Engine runs containers from images, managed by the Daemon, controlled via the CLI, and orchestrated by Compose.
Explain the terminology: Docker Compose, Dockerfile, Docker Image, Docker Container.
Docker Compose: Tool for defining and running multi-container Docker applications.
Dockerfile: Script with instructions to build a Docker image.
Docker Image: A template for creating Docker containers.
Docker Container: An isolated environment to run applications.
In what real scenarios have you used Docker?
- Deploying microservices, CI/CD pipelines, isolating development environments, and running legacy applications.
Docker vs Hypervisor?
Docker: Lightweight containers sharing the host OS kernel.
Hypervisor: Virtual machines with full OS, more resource-intensive.
Advantages and disadvantages of Docker?
Advantages: Portability, efficiency, scalability, and faster deployment.
Disadvantages: Security concerns, networking complexity, and data persistence issues.
What is a Docker namespace?
- A feature for isolating resources (e.g., PID, network) in containers.
What is a Docker registry?
- A storage and distribution system for Docker images (e.g., Docker Hub).
What is an entry point?
- The command that runs as the main process inside a container.
How to implement CI/CD in Docker?
- Use Docker to build, test, and deploy containers in automated CI/CD pipelines.
Will data on the container be lost when the Docker container exits?
- Yes, data is lost when a container exits unless volumes or bind mounts are used to backup the container data.
What is a Docker swarm?
- A native clustering and orchestration tool for Docker containers.
What are docker commands for the following:
Viewing running containers:
docker ps
Running a container under a specific name:
docker run --name <name> <image>
Exporting a Docker image:
docker save -o <file> <image>
Importing an existing Docker image:
docker load -i <file>
Deleting a container:
docker rm <container_id>
Removing all stopped containers, unused networks, build caches, and dangling images:
docker system prune
What are the common Docker practices to reduce the size of Docker images?
- Multi-stage builds, using smaller base images, minimizing layers, and cleaning up after package installations.
How do you troubleshoot a Docker container that is not starting?
- Check logs with
docker logs <container_id>
, inspect withdocker inspect
, and verify configuration files.
- Check logs with
Docker networking model:
- Docker uses bridge, overlay, host, and macvlan networks to connect containers.
How do you manage persistent storage in Docker?
- Use Docker volumes or bind mounts to persist data outside the container lifecycle.
How do you secure a Docker container?
- Limit privileges, use secure base images, scan images for vulnerabilities, and use Docker security features like seccomp and AppArmor.
What is docker overlay networking:
- A network that allows containers across different hosts to communicate securely in a Docker Swarm.
How do you handle environment variables in Docker?
- Pass environment variables using
-e
or--env-file
options when running containers.
- Pass environment variables using
I hope these questions will surely help you ace your next interview for Docker. Happy learning! ๐
Subscribe to my newsletter
Read articles from Deepesh Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Deepesh Gupta
Deepesh Gupta
DevOps & Cloud Enthusiast | Open Source Contributor | Driving Technological Excellence in DevOps and Cloud Solutions