Day 21 : Docker Important interview Questions.

Day 21 : Docker Important interview 
                                Questions.

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

  • Image: A Docker image is a lightweight, standalone, executable package that includes everything needed to run a piece of software, including the code, a runtime, libraries, and environment variables.

  • Container: A Docker container is a runnable instance of a Docker image. It runs applications in isolated environments on a host system.

  • Engine: The Docker engine is the software responsible for building, running, and managing containers. It includes a server and a REST API, allowing users to interact with it.

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

  • Both COPY and ADD are Dockerfile instructions.

  • COPY is used to copy files and directories from the host to the container.

  • ADD has additional features like URL support and can unpack compressed files. If you don't need these extra features, it's recommended to use COPY for simplicity.

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

  • CMD is used to provide default arguments for the entry point of the container. It specifies what command to run when the container starts.

  • RUN is used during the image build to execute commands and create layers. It is used for installing packages, updating the system, etc.

    How Will you reduce the size of the Docker image?

    • Use a smaller base image.

    • Minimize the number of layers in your image.

    • Remove unnecessary files after installing dependencies.

    • Combine multiple RUN commands into one.

    • Use multi-stage builds to reduce the final image size.

Why and when to use Docker?

  • Docker is used for containerization, providing a consistent and reproducible environment for applications.

  • It's beneficial in scenarios where you want to isolate dependencies, ensure consistency across different environments, and streamline the deployment process.

Explain the Docker components and how they interact with each other

  • Docker Compose: A tool for defining and running multi-container Docker applications.

  • Docker File: A script containing instructions to build a Docker image.

  • Docker Image: A lightweight, standalone, and executable software package.

  • Docker Container: An instance of a Docker image running as a process.

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

  1. Docker Compose:

    • Definition: Tool for defining and running multi-container Docker applications.

    • Purpose: Simplifies the management of multi-container setups using a YAML configuration file.

  2. Docker File:

    • Definition: Script containing instructions to build a Docker image.

    • Purpose: Defines the environment, dependencies, and commands to build a reproducible Docker image.

  3. Docker Image:

    • Definition: Lightweight, standalone, executable package with all components needed to run software.

    • Purpose: Portable and consistent unit for packaging and distributing applications.

  4. Docker Container:

    • Definition: Runnable instance of a Docker image.

    • Purpose: Provides isolated, executable environments, ensuring consistency across different platforms and deployments.

In what real scenarios have you used Docker?

  • Microservices Architecture: Deploying and managing individual services independently.

  • Continuous Integration/Continuous Deployment (CI/CD): Building, testing, and deploying applications in an automated and reproducible way.

  • Development Environments: Ensuring consistency between development and production environments.

  • Scalable Deployments: Easily scaling applications horizontally by deploying containers across multiple hosts or in container orchestration systems like Kubernetes.

Docker vs Hypervisor?

  • Docker uses containerization, sharing the host OS kernel, making it more lightweight and faster.

  • Hypervisors virtualize the entire operating system, leading to heavier resource usage.

What are the advantages and disadvantages of using docker?

  • Advantages: Portability, Isolation, Resource Efficiency, Rapid Deployment, Version Control.

  • Disadvantages: Learning Curve, Limited GUI, Security Concerns (if not properly configured)

What is a Docker namespace?

Namespaces in Docker provide isolation for containers. They ensure that processes within a container are isolated from processes in other containers and from the host system.

What is a Docker registry?

A Docker registry is a storage and content delivery system for named Docker images. Docker clients pull images from registries to run containers.

What is an entry point?

The entry point is the command that is run when the container starts. It can be specified in the Dockerfile using the ENTRYPOINT instruction

How to implement CI/CD in Docker?

  • Use CI tools (e.g., Jenkins, GitLab CI) to build Docker images automatically.

  • Push the built images to a Docker registry.

  • Use CD tools to deploy and manage containers based on these images.

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

By default, data within a container's filesystem is not lost when the container exits unless explicitly removed or configured otherwise.

What is a Docker swarm?

Docker Swarm is Docker's native clustering and orchestration solution. It allows you to create and manage a swarm of Docker nodes, turning them into a single, virtual Docker host.

What are the docker commands for the following

1 . view running containers

docker ps

2 . command to run the container under a specific name

docker run --name <container_name>

3 . command to export a docker

docker save -o <output_file.tar> <image_name>

4 . command to import an already existing docker image

docker load -i <input_file.tar>

5 . commands to delete a container

docker rm <container_id or container_name>

6 . command to remove all stopped containers, unused networks, build caches, and dangling images?

docker system prune -a

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

  • Use a minimal base image.

  • Avoid unnecessary packages and dependencies.

  • Optimize layers and minimize the number of commands.

  • Remove unnecessary files after installations.

  • Use multi-stage builds.

Happy Learning :)