Docker's important interview questions
Docker Interview
Docker is a good topic to ask in DevOps Engineer Interviews, mostly for freshers. One must surely try these questions in order to be better at Docker.
Questions -
Difference between Image, Container, and Engine:
Image: A blueprint holding software and dependencies.
Container: A live instance of an image, isolated and portable.
Engine: Docker toolset for building, running, and managing containers.
Difference between Docker COPY vs ADD:
COPY: Straightforward file copying during the image build.
ADD: Also supports URL fetching and auto-extraction.
Difference between Docker CMD vs RUN:
RUN: Executes commands during image build.
CMD: Sets the default command when a container starts.
Reducing Docker Image Size:
Use smaller base images like Alpine Linux.
Minimize layers, and remove unused files.
Optimize Dockerfile instructions.
Clear caches in the same RUN command.
Why and when to use Docker?:
Docker simplifies deployment, scaling, and consistency.
It's ideal for microservices, continuous integration, and isolated environments.
Explain Docker Components and Interaction:
The Docker Engine includes the daemon, CLI, and REST API.
Docker images, built from Dockerfiles, are stored in the registry.
Containers are running instances of images, isolated and lightweight.
Explain Terminology: Docker Compose, Docker File, Docker Image, Docker Container:
Docker Compose: Defines multi-container setups.
Docker File: Script containing build instructions.
Docker Image: Blueprint of an application and its dependencies.
Docker Container: Live instance of an image, isolated.
Real Scenarios of Using Docker:
Setting up consistent development environments.
Deploying microservices architectures.
Enabling smooth CI/CD pipelines and efficient scaling.
Docker vs Hypervisor:
Docker offers lightweight OS-level virtualization.
Hypervisors provide full-fledged virtual machines.
Advantages and Disadvantages of Using Docker:
Advantages: Isolation, resource efficiency, consistency.
Disadvantages: Limited kernel support, and security concerns.
Docker Namespace:
- Docker uses namespaces to isolate processes within a container.
Docker Registry:
- A registry stores and shares Docker images, like Docker Hub.
Entry Point:
- The command that runs when a container starts.
Implementing CI/CD in Docker:
Utilize version-controlled Dockerfiles.
Automate image builds, testing, and deployment using CI tools.
Employ orchestration tools like Kubernetes or Docker Swarm.
Data Loss on Container Exit:
- Data on a container's filesystem is lost without proper data persistency mechanisms like volumes.
Docker Swarm:
- Docker Swarm is Docker's native orchestration solution for managing and scaling containers.
Docker Commands:
To view running containers:
docker ps
.To run a container with a specific name:
docker run --name
.To export a container:
docker export
.To import an existing Docker image:
docker import
.To delete a container:
docker rm
.To remove stopped containers, unused networks, build caches, and dangling images:
docker system prune
.
Common Docker Practices to Reduce Image Size:
Opt for smaller base images (like Alpine Linux).
Minimize Dockerfile layers and remove unused files.
Clear package caches within the same RUN instruction.
Hope this Blog on Docker's interview questions was helpful and handy.