Docker Interview Essentials:

A Comprehensive Guide to Nail Your Interview.

Docker Interview Essentials:

What is the Difference between Image, Container & Engine?

Docker image is a packaged software bundle, the Docker container is a running instance of an image, and the Docker Engine is the software that orchestrates and manages containers. Together, these components provide a powerful toolset for creating, deploying, and managing applications using containers.

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

COPY is a docker file command that copies files from a local source location to a destination in the Docker container. ADD command is used to copy files/directories into a Docker image.

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

RUN is an image build step, the state of the container after a RUN command will be committed to the container image. A Dockerfile can have many RUN steps that layer on top of one another to build the image. CMD is the command the container executes by default when you launch the built image.

How to reduce the size of the Docker image?

To reduce Docker image size:

  • Begin with a minimal base image like Alpine Linux.

  • Use multi-stage builds to minimize layers.

  • Optimize Dockerfile instructions, and avoid unnecessary files.

  • Utilize .dockerignore to exclude files.

  • Minimize installed packages and use smaller alternatives.

  • Combine package installations and cleanup in the same layer.

  • Clean up logs, caches, and unnecessary tools.

  • Employ multi-stage builds for smaller runtime images.

  • Regularly use docker image prune to remove unused images.

Why and when to use Docker?

Docker streamlines the development lifecycle by allowing developers to work in standardized environments using local containers which provide your applications and services. Containers are great for continuous integration and continuous delivery (CI/CD) workflows.

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

Docker employs a client-server design. A Docker client communicates with the daemon (that develops, operates, and distributes Docker containers). REST application programming interfaces (APIs) are used for network communication and UNIX sockets between the client and daemon.

Explain the terminology: Docker Compose, Docker File, Docker Image, Docker Container?

Docker Compose helps manage multi-container applications, Dockerfile defines how to build an image, Docker image is a packaged application with all its dependencies, and Docker container is a running instance of an image that encapsulates the application's runtime environment. These concepts are fundamental to understanding and effectively using Docker for application deployment and management.

Docker vs Hypervisor?

The difference between hypervisors and Dockers is how they start and use resources. There are two types of hypervisors: the bare metal runs directly on the hardware while the second type runs on the operating system. Docker, on the other hand, runs on the host kernel itself.

What are the Pros and Cons of using docker?

Pros of Docker:

  • It is lightweight because it does not require any resource pre-allocation (RAM). Whenever it needs resources it acquires them from the host OS. It is of less cost.

  • Continuous integration efficiency. Docker enables you to build a container image and use that same image across every step of the deployment process.

  • It can run on physical hardware, virtual hardware and on the cloud.

  • You can re-use the image.

  • It takes very less time to create.

Cons of Dockers:

  • Docker is not good for an application that requires a rich GUI.

  • It is difficult to manage large amounts of containers.

  • Docker does not provide cross-platform compatibility means if an application is designed to run in a Docker container on Windows, then it cannot run on a Linux Docker container.

  • Docker is suitable when the development OS and testing OS are the same.

  • It does not provide any solution for data backup and recovery.

What is a Docker namespace?

Docker uses a technology called namespaces to provide the isolated workspace called the container. When you run a container, Docker creates a set of namespaces for that container. These namespaces provide a layer of isolation.

What is a Docker registry?

A Docker registry is a storage and distribution system for named Docker images. The same image might have multiple different versions, identified by their tags. A Docker registry is organized into Docker repositories, where a repository holds all the versions of a specific image.

What is an EntryPoint?

EntryPoint is one of the many instructions you can write in a docker file. The EntryPoint instruction is used to configure the executables that will always run after the container is initiated.

How to implement CI/CD in Docker?

  1. Code Management: Use Git to track code changes.

  2. Choose Tool: Pick a CI/CD tool (e.g., Jenkins, GitHub Actions).

  3. Dockerize: Create Dockerfile for your app.

  4. Pipeline Steps:

    • Build: Tool makes app ready for Docker.

    • Test: Check app works correctly.

    • Deploy: Put app on servers using Docker.

  5. Automate: Set up automatic deployment process.

  6. Monitor: Keep an eye on app's performance.

  7. Learn: Use feedback to improve your app and process.

  8. Security: Keep app and image secure.

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

Not at all! Any data that your application writes to disk gets preserved in its container until you explicitly delete the container.

What is a Docker swarm?

A Docker Swarm is a group of either physical or virtual machines that are running the Docker application and that have been configured to join together in a cluster. The activities of the cluster are controlled by a swarm manager, and machines that have joined the cluster are referred to as nodes.

Docker commands for the following:

  • docker ps or docker container ls: View running containers.

  • docker run --name: Run the container under a specific name.

  • docker export: To export a docker image.

  • docker import: To import a docker image.

  • docker container prune: commands to delete a container.