Day21 ----> 90DaysOfDevOps Challenge @TWS

Day21 ----> 90DaysOfDevOps Challenge @TWS

Day 21 Task: Docker Important Interview Questions.

  1. What is the Difference between an Image, Container and Engine?
  • An image is an executable package that includes everything needed to run an application, including the code, libraries, dependencies, and runtime.

  • A container is an instance of an image that runs as a process in isolation from other processes on the host machine. It provides a way to package and run applications in a portable and reproducible manner.

  • The Docker engine is the core component of Docker running on the host operating system that enables the creation, management, and execution of containers.

  1. What is the Difference between the Docker command COPY vs ADD?
  • COPY is used to copy files and directories from the host machine to the container.

  • ADD allows for remote URLs to be used as the source of the copy. ADD can also extract archives (tar, gzip, bzip2) and download files from URLs.

  1. What is the Difference between the Docker command CMD vs RUN?
  • RUN is used to execute commands during the build process of an image

  • CMD is used to specify the default command to be run when a container is launched from an image.

  1. How Will you reduce the size of the Docker image?
  • Use a smaller base image.

  • Remove unnecessary files and directories.

  • Combine multiple RUN commands into one.

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

  • Use multi-stage builds.

  • Minimize the number of layers in the image.

  1. Why and when to use Docker?

    Docker is used to package and run applications in a portable and isolated environment.

    It can be used in various scenarios, such as:

  • Development and testing of applications

  • Continuous integration and continuous deployment (CI/CD) pipelines

  • Cloud-native applications

  1. Explain the Docker components and how they interact with each other. Docker consists of several components, including:
  • Docker engine: The core component of Docker that enables the creation, management, and execution of containers.

  • Docker client: The command-line tool used to interact with the Docker daemon.

  • Docker registry: A centralized location for storing and sharing Docker images.

  • Docker image: An executable package that includes everything needed to run an application.

  • Docker container: An instance of an image that runs as a process in isolation from other processes on the host machine.

  • Dockerfile: A text file that contains instructions for building a Docker image.

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

    These components interact with each other through APIs and protocols to create and manage Docker applications.

  1. Explain the terminology: Docker Compose, Docker File, Docker Image, Docker Container?
  • Docker Compose: A tool for defining and running multi-container Docker applications.

  • Docker File: A text file that contains instructions for building a Docker image.

  • Docker Image: An executable package that includes everything needed to run an application.

  • Docker Container: An instance of an image that runs as a process in isolation from other processes on the host machine.

  1. In what real scenarios have you used Docker?
  • Dockerized my Python application to run it on different platforms.

  • Continuous integration and continuous deployment (CI/CD) pipelines

  1. Docker vs Hypervisor?
  • Docker uses containerization to run applications, while Hypervisors use virtualization to create virtual machines.

  • Containers are lightweight and provide faster startup times and better resource utilization than virtual machines.

  • Docker is suitable for running applications that require isolation at the process level, while hypervisors are suitable for running applications that require full isolation at the hardware level.

  1. What are the advantages and disadvantages of using docker?

Advantages:

  • Provides a consistent environment to run apps across different systems

  • Easy to package and deploy applications

  • Resource-efficient compared to traditional virtualization

  • Removes dependency issues

  • Facilitates microservices architecture

Disadvantages:

  • Can add complexity to development and deployment workflows

  • Requires additional management and monitoring compared to traditional deployments

  • Performance overhead when running certain workloads.

  • Introduces some challenges around networking, particularly when containers need to communicate with each other or with external services.

  1. What is a Docker namespace?

    A Docker namespace is a mechanism for providing isolation or a separate environment for system resources used by Docker containers, such as network interfaces, process IDs, and file systems.

    Docker uses different namespaces, such as PID namespace, network namespace, and mount namespace, to isolate containers from each other and the host system.

  2. What is a Docker registry?

    A Docker registry is a centralized location for storing and sharing Docker images. It allows users to push and pull images to and from the registry, making it easy to distribute and deploy Docker applications across different systems.

  3. What is an entry point?

    An ENTRYPOINT is a command that is run when a Docker container is launched from an image. It specifies the main command or executable that should be run inside the container. The entry point can be specified in the Dockerfile or overridden at runtime with the docker run command.

  4. How to implement CI/CD in Docker?
    Implementing CI/CD with Docker involves steps:

    1. Build Docker images: Write a Dockerfile for your application and build the Docker images that contain your application code and its dependencies.

    2. Push the Docker images to a registry: Push the built Docker images to a Docker registry, such as Docker Hub, so that they can be accessed by other systems.

    3. Set up a CI/CD pipeline: Use a CI/CD tool, such as Jenkins, to set up a pipeline that automates the process of building, testing, and deploying your application in Docker containers. This pipeline should include the following steps:

      • Pull the latest version of your code from your code repository.

      • Build the Docker images using the Dockerfile and push them to the Docker registry.

      • Run automated tests on the Docker images to ensure that they are functioning correctly.

      • Deploy the Docker images to the production environment.

    4. Use orchestration tools: Once your application is running in Docker containers, you can use orchestration tools, such as Kubernetes or Docker Swarm, to manage and scale the containers as needed.

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

    It depends on how the container was created and configured. By default, any changes made inside a container are only saved in the container's writable layer, which is deleted when the container is removed or stopped.

    However, you can use Docker volumes or bind mounts to persist data outside the container's writable layer, so that it is not lost when the container is removed or stopped.

  6. What is a Docker swarm?

    Docker swarm is a container orchestration tool that enables the management and scaling of a cluster of Docker nodes. It allows you to deploy and manage containers across multiple hosts in a decentralized manner, providing high availability and fault tolerance.

  7. 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 [name] [image]

  • command to export a docker: docker export [container] > [file.tar]

  • command to import an already existing docker image: docker load < [file.tar]

  • commands to delete a container: docker rm [container]

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

  1. What are the common Docker practices to reduce the size of Docker Images?

    Some common practices to reduce the size of Docker images include:

    • Use a smaller base image: Choose a smaller base image, such as Slim, bull-eye, Buster, Alpine or BusyBox, instead of a full-fledged operating system like Ubuntu or Debian.

    • Minimize layers: Reduce the number of layers in the Docker image by combining commands into a single layer.

    • Multi-staging: Using multi-stage builds to discard unneeded build artifacts.

    • Use a .dockerignore file to exclude unnecessary files and directories from the Docker build context, which can significantly reduce the size of the resulting image.

    • Compress files and directories: Compress large files and directories before adding them to the Docker image, and decompress them when the container starts.

    • Remove unnecessary packages: Remove any unnecessary packages and dependencies from the image to reduce its size.

Day 21 task is completed!

90DaysOfDevOps Tasks👇

github.com/Chaitannyaa/90DaysOfDevOps.git

Chaitannyaa Gaikwad | LinkedIn