Skip to main content

Command Palette

Search for a command to run...

Day 21 : Docker Interview Questions

Published
4 min readView as Markdown
Day 21 : Docker Interview Questions
A

A DevOps Engineer ♾ with a passion for learning and improving. I believe that the only limits we have are the ones we set for ourselves and I'm excited to see how far I can go with my career. With hard work and dedication, I'm confident that I can create something that really makes a difference.❤🕊

Q: What is the Difference between an Image, Container, and Engine?

A:

  • Image: An image is a template containing everything needed to run an application, including code, runtime, libraries, and dependencies.

  • Container: A container is an instance of an image running as a process on the host machine, isolated from other containers and the host system.

  • Engine: The Docker Engine is the core component responsible for creating and managing Docker containers. It includes the Docker daemon, API, and CLI.

Q: What is the Difference between the Docker command COPY vs ADD?

A:

  • COPY: Copies files or directories from the host machine to the container's filesystem. Recommended for copying local files into the container.

  • ADD: Similar to COPY but with additional features like URL support and automatic tar extraction. Use cautiously to avoid unexpected behavior.

Q: What is the Difference between the Docker command CMD vs RUN?

A:

  • CMD: Defines the default command to run when the container starts. Often used to specify the main application process.

  • RUN: Executes commands during the image build process to install dependencies, configure the environment, or perform other setup tasks.

Q: How Will you reduce the size of the Docker image?

A:

  • Use multi-stage builds.

  • Choose lightweight base images like Alpine Linux.

  • Minimize the number of layers.

  • Remove unnecessary files and dependencies.

  • Use .dockerignore file to exclude unnecessary files and directories.

Q: Why and when to use Docker?

A:

  • Docker simplifies application deployment by packaging applications and their dependencies into containers.

  • Provides consistency across different environments, making it easier to develop, test, and deploy applications.

  • Commonly used in microservices architectures, CI/CD pipelines, and cloud-native applications.

Q: Explain the Docker components and how they interact with each other.

A:

  • Docker Compose: Defines and runs multi-container Docker applications using a YAML file.

  • Dockerfile: Contains instructions for building a Docker image.

  • Docker Image: Read-only template used to create Docker containers.

  • Docker Container: Runnable instance of a Docker image.

Q: In what real scenarios have you used Docker?

A:

  • Deploying microservices-based applications.

  • Creating development environments with consistent dependencies.

  • Scaling applications horizontally with Docker Swarm or Kubernetes.

  • Building CI/CD pipelines for automated testing and deployment.

Q: Docker vs Hypervisor?

A:

  • Docker containers share the host OS kernel, resulting in lower overhead compared to hypervisors.

  • Hypervisors create virtual machines with their own OS, leading to higher resource consumption.

Q: What are the advantages and disadvantages of using Docker?

A:

  • Advantages: Portability, scalability, isolation, efficiency, and easy management.

  • Disadvantages: Security concerns, learning curve, potential performance overhead.

Q: What is a Docker namespace?

A:

  • Docker uses namespaces to provide isolation for containers, allowing each container to have its own view of system resources like processes, network interfaces, and filesystems.

Q: What is a Docker registry?

A:

  • A Docker registry is a repository for Docker images. Docker Hub is the default public registry, but organizations can also set up private registries to store and share custom images.

Q: What is an entry point?

A:

  • The ENTRYPOINT instruction in a Dockerfile defines the command that will be executed when the container starts. It is similar to CMD but cannot be overridden at runtime.

Q: How to implement CI/CD in Docker?

A:

  • Use Docker to package applications and dependencies into containers.

  • Integrate Docker with CI/CD tools like Jenkins, GitLab CI, or Travis CI.

  • Automate the build, test, and deployment processes using Docker images and containers.

Q: Will data on the container be lost when the docker container exits?

A:

  • Yes, data stored within a container's writable layer is lost when the container exits unless it is explicitly persisted using volumes or bind mounts.

Q: What is a Docker swarm?

A:

  • Docker Swarm is a native clustering tool for Docker containers that allows you to create and manage a cluster of Docker hosts.

Q: What are the docker commands for the following:

  • View running containers: docker ps

  • Command to run the container under a specific name: docker run --name <container_name>

  • Command to export a docker: docker export <container_id>

  • Command to import an already existing docker image: docker import <file_path>

  • Commands to delete a container: docker rm <container_id>

  • Command to remove all stopped containers, unused networks, build caches, and dangling images: docker system prune

Q: What are the common docker practices to reduce the size of Docker Image?

A:

  • Use multi-stage builds.

  • Minimize layers and combine commands.

  • Choose smaller base images.

  • Remove unnecessary files and dependencies.

  • Compress files and use efficient build techniques.


✉Endcard:

🎉 Thank you for joining me on this insightful journey into the world of DevOps!

❤ If you found this blog helpful and informative, don't forget to give it a like!

🔄 Share this valuable knowledge with your friends and colleagues, so they can also benefit from understanding the power of DevOps!

👉 Stay updated with my latest posts and never miss out on exciting content! Click that Follow button to join and stay in the loop!

Follow me on LinkedIn -->abdallah-qamar👔

Stay tuned for Day 22...👋

90 Days Of DevOps

Part 21 of 22

In this series, we will explore the core principles of DevOps following a 90 day roadmap.

Up next

Day 22 : What is Jenkins ?

Introduction to Jenkin Pipelines.