Day 21 Task: Important Docker Interview Questions

Shivani SinghShivani Singh
4 min read

1. What is the difference between an Image, Container, and Engine?

  • Image: A read-only template with application code and dependencies that is used to create containers.

  • Container: A running instance of an image that contains an isolated environment for the application.

  • Engine: The Docker Engine is the core component that runs on the host OS, allowing users to build, run, and manage containers.

2. Difference between COPY vs ADD in Docker

  • COPY: Only copies files and directories from the host filesystem into the image.

  • ADD: More versatile; it can also copy files from URLs and automatically extract compressed files.

3. Difference between CMD vs RUN in Docker

  • CMD: Sets the default command that will run when a container starts. Only one CMD command is used per Dockerfile, and it can be overridden.

  • RUN: Executes a command at build time and creates a new image layer. Used to install packages and set up the environment.

4. How will you reduce the size of a Docker image?

  • Use a lightweight base image like alpine.

  • Combine RUN commands to reduce layers.

  • Clean up unnecessary files after installations.

  • Use .dockerignore to exclude unneeded files from the build context.

5. Why and when should you use Docker?

  • Docker is ideal for creating consistent, isolated application environments across development, testing, and production. It’s especially useful for microservices, CI/CD pipelines, and complex applications with multiple services.

6. Explain Docker components and how they interact

  • Docker CLI: Command-line interface to interact with the Docker Engine.

  • Docker Engine: Core engine that builds and runs containers.

  • Docker Daemon: Runs on the host and manages images, containers, networks, and volumes.

  • Docker Registry: Stores Docker images; Docker Hub is the default registry.

7. Explain the terminology

  • Docker Compose: Tool to manage multi-container Docker applications.

  • Dockerfile: Script that contains commands for creating a Docker image.

  • Docker Image: Blueprint from which containers are created.

  • Docker Container: Running instance of a Docker image.

8. In what real scenarios have you used Docker?

  • Implementing microservices architecture.

  • Setting up CI/CD pipelines for testing and deployment.

  • Creating isolated development environments to avoid dependency conflicts.

9. Docker vs Hypervisor

  • Docker containers are lightweight and share the host OS, while hypervisors run full OS VMs. Containers are faster and more resource-efficient, but VMs provide stronger isolation.

10. Advantages and disadvantages of Docker

  • Advantages: Portability, fast startup, resource efficiency, consistent environments.

  • Disadvantages: Limited OS compatibility (Linux-focused), weaker security isolation compared to VMs.

11. What is a Docker namespace?

  • Namespaces are Linux kernel features used by Docker to isolate containers, covering process IDs, network access, and file system access.

12. What is a Docker registry?

  • A storage location for Docker images. The default registry is Docker Hub, where users can push and pull images.

13. What is an entry point?

  • An ENTRYPOINT defines the main application or command for the container. Unlike CMD, it cannot be overridden easily, making it ideal for specifying the main executable.

14. How to implement CI/CD in Docker?

  • Integrate Docker with CI/CD tools like Jenkins, GitLab CI, or GitHub Actions to automate testing, building, and deploying Docker containers at each stage of the pipeline.

15. Will data on the container be lost when the Docker container exits?

  • Yes, unless data is stored in volumes, which are independent of the container's lifecycle.

16. What is a Docker swarm?

  • Docker Swarm is Docker’s native orchestration tool for managing clusters of Docker nodes, enabling the deployment and scaling of services.

17. Docker commands for various tasks

  • View running containers: docker ps

  • Run a container under a specific name: docker run --name <name> <image>

  • Export a Docker image: docker save -o <path> <image>

  • Import an existing Docker image: docker load -i <path>

  • Delete a container: docker rm <container-id>

  • Remove unused resources: docker system prune

18. Common Docker practices to reduce image size

  • Use multi-stage builds, clean up unnecessary files, use .dockerignore, and leverage smaller base images.

19. How do you troubleshoot a Docker container that is not starting?

  • Check logs with docker logs <container-id>, inspect the configuration, verify port bindings, and check Dockerfile for errors.

20. Docker networking model

  • Docker provides various networking options, including bridge, host, overlay, and macvlan networks to connect containers on the same host or across multiple hosts.

21. Managing persistent storage in Docker

  • Use Docker volumes or bind mounts to persist data outside the container, ensuring it remains even if the container is removed.

22. How do you secure a Docker container?

  • Use non-root users, keep images updated, scan images for vulnerabilities, restrict container privileges, and manage secrets securely.

23. What is Docker overlay networking?

  • Overlay networking enables communication between Docker containers across different hosts in a swarm, useful for orchestrated multi-host applications.

24. How do you handle environment variables in Docker?

  • Pass environment variables at runtime with -e VAR=VALUE or using .env files, and reference them in the Dockerfile or Docker Compose configuration.

These questions will help you in your next DevOps interview.

Docker’s power lies in its portability and efficiency, making it ideal for CI/CD, microservices, and cloud deployments. Perfect your Docker fundamentals and make containerization work for you!

#Docker #Containers #DevOps #CloudComputing #Microservices

0
Subscribe to my newsletter

Read articles from Shivani Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shivani Singh
Shivani Singh

"Passionate about simplifying the complexities of DevOps, I bring 5 years of hands-on experience in supporting development and operations teams to achieve faster, more reliable software delivery. I thrive on optimizing CI/CD pipelines, automating workflows, and troubleshooting challenges across diverse cloud environments. My expertise spans across infrastructure management, continuous integration, and performance monitoring—ensuring stability and efficiency at every stage of the software lifecycle. Always eager to learn, collaborate, and innovate, I’m committed to driving impactful change in the DevOps space."