Day 21: Docker Important interview Questions.

Table of contents
- Difference between an Image, Container, and Engine:
- Difference between Docker command COPY vs ADD:
- Difference between Docker command CMD vs RUN:
- How to reduce the size of the Docker image:
- Why and when to use Docker:
- Explanation of Docker components and terminology:
- Real scenarios of using Docker:
- Docker vs Hypervisor:
- Advantages and disadvantages of Docker:
- Docker namespace:
- Docker registry:
- Entry point:
- Implementing CI/CD in Docker:
- Data persistence in Docker containers:
- Docker swarm:
- Common Docker commands:
- Common Docker practices to reduce image size:
In a DevOps interview focused on Docker, concise and precise answers are essential. Let's address each question succinctly:
Difference between an Image, Container, and Engine:
Image: A blueprint for creating containers. It contains all the dependencies needed to run an application.
Container: A runtime instance of an image. It encapsulates the application and its dependencies, isolated from the host system.
Engine: The software that enables building, managing, and running containers. Docker Engine is a popular containerization platform.
Difference between Docker command COPY vs ADD:
COPY: Copies files or directories from the host into the container filesystem.
ADD: Similar to COPY but with additional features like remote URL support and automatic tar extraction, which makes it more versatile.
Difference between Docker command CMD vs RUN:
CMD: Specifies the default command to execute when a container starts. It's often used to define the primary application process.
RUN: Executes commands during image build time. It's typically used for installing dependencies or setting up the environment.
How to reduce the size of the Docker image:
Use multi-stage builds.
Minimize the number of layers.
Remove unnecessary files and dependencies.
Utilize Alpine Linux as a base image for smaller footprint.
Optimize Dockerfile instructions.
Why and when to use Docker:
Docker enables consistent development, shipping, and deployment of applications across different environments.
It's useful in microservices architecture, continuous integration/continuous deployment (CI/CD), and scaling applications.
Explanation of Docker components and terminology:
Docker Compose: Tool for defining and running multi-container Docker applications.
Docker File: Text file containing instructions for building Docker images.
Docker Image: Blueprint for containers, including application code and dependencies.
Docker Container: Runnable instance of a Docker image.
Real scenarios of using Docker:
Development environments.
Continuous integration and deployment pipelines.
Microservices architecture.
Scaling applications.
Docker vs Hypervisor:
- Docker containers share the host OS kernel, making them lightweight and faster to start compared to virtual machines managed by hypervisors.
Advantages and disadvantages of Docker:
Advantages: Portability, scalability, resource efficiency.
Disadvantages: Limited support for Windows environments, security concerns with shared kernel.
Docker namespace:
- A namespace provides isolation for resources within a container, such as network interfaces, process IDs, and filesystem mounts.
Docker registry:
- A centralized repository for storing and distributing Docker images.
Entry point:
- The initial command or script executed when a container starts.
Implementing CI/CD in Docker:
Use Docker images for building, testing, and deploying applications.
Automate Docker image builds and deployments using CI/CD tools like Jenkins or GitLab CI.
Data persistence in Docker containers:
- Data within a container is typically lost when the container exits unless specifically stored in persistent volumes or external storage.
Docker swarm:
- Docker swarm is a clustering and orchestration tool used to manage a cluster of Docker hosts.
Common Docker commands:
View running containers:
docker ps
Run container under a specific name:
docker run --name <name>
Export a Docker image:
docker save
Import an existing Docker image:
docker load
Delete a container:
docker rm
Remove all stopped containers, unused networks, build caches, and dangling images:
docker system prune
Common Docker practices to reduce image size:
Use lightweight base images.
Minimize the number of layers.
Remove unnecessary files and dependencies.
Optimize Dockerfile instructions.
Subscribe to my newsletter
Read articles from Yashraj Singh Sisodiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Yashraj Singh Sisodiya
Yashraj Singh Sisodiya
I am Yashraj Singh Sisodiya, a 3rd Year CSE student at SVVV, born and raised in Shujalpur. Currently residing in Indore, I'm passionate about pursuing a career in DevOps engineering. My tech journey began with an internship at Infobyte, honing my skills as an Android Developer intern. Alongside my academic pursuits, I actively participate in co-curriculars, holding roles as Technical Lead at Abhyudaya and Cloud Lead at GDSC SVVV, while also serving as an MLSA of my college. I have a keen interest in Cloud Computing, demonstrated through projects such as User management and Backup using shell scripting Linux, Dockerizing applications, CI/CD with Jenkins, and deploying a 3-tier application on AWS. Always eager to learn, I'm committed to expanding my knowledge and skills in the ever-evolving tech landscape.