DevOps, Day - 21

DevOps, Day - 21

Docker Important interview Questions.

Let's see some interesting interview questions on docker πŸ˜ƒ

Interview Questions With Deep Meaningful Answers :)

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

    • Image: An image is a package that contains all the necessary dependencies and instructions to run a software application.

    • Container: A container is an instance of an image that runs the application in an isolated environment.

    • Engine: An engine, also known as the container runtime, is the software responsible for creating and managing containers.

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

    • COPY: Copies files and directories from the host machine to the container image.

      Has a simpler syntax compared to ADD.

      Cannot extract local tar files or fetch remote URLs.

      Recommended to use for basic file and directory copying operations.

    • ADD: Copies files and directories from the host machine to the container image.

      Can extract local tar files and fetch remote URLs, which can be useful for some use cases.

      Has a more complex syntax compared to COPY.

      Can be used for more advanced use cases that require additional features beyond basic file copying.

      [It is recommended to use COPY for simple copying of files and directories and use ADD when additional features are required]

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

    Both CMD and RUN are Dockerfile commands used to configure the behaviour of a container image. The main difference is that RUN is used to execute commands during the build process of an image, while CMD is used to specify the default command to run when a container is started from the image.

    Here are some additional points:

    • RUN: Executes commands during the build process of an image.

      Creates a new layer in the image.

      Can be used to install software, update packages, or execute any other command that is required during image building.

    • CMD: Specifies the default command to run when a container is started from the image.

      Only one CMD instruction can be specified in a Dockerfile.

      If multiple CMD instructions are specified, only the last one will be used.

      If a CMD instruction is provided when running a container, it will override the CMD specified in the Dockerfile.

  4. How Will you reduce the size of the Docker image?

    • To reduce the size of a Docker image, use a smaller base image, remove unnecessary files, optimize Dockerfile instructions, and use a .dockerignore file to prevent unnecessary files from being included in the build context.

    • Compress files that are copied into the image using gzip or similar tools, then decompress them in the container when required.

    • These best practices can significantly reduce the size of Docker images and improve the efficiency of your containerized applications.

  5. Why and when to use Docker?

    • Docker is used to simplify application deployment, enhance portability, and improve consistency across different environments.

    • It achieves this by packaging applications in containers, which are lightweight and can be easily moved between different environments, such as development, testing, and production.

    • Docker also provides an efficient and standardized way to manage dependencies and run applications, which can save time and reduce errors.

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

    Docker has three main components: the Docker engine, Docker images, and Docker containers.

    • The Docker engine manages the lifecycle of Docker containers and runs on the host machine.

    • Docker images are read-only templates that define the environment and configuration of a Docker container.

    • Docker containers are instances of Docker images that can be run, started, stopped, and deleted.

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

    • Docker Compose: A tool for running multiple Docker containers as a single service.

    • Dockerfile: A script that defines the steps needed to build a Docker image.

    • Docker Image: A packaged environment that includes all the files needed to run an application.

    • Docker Container: An instance of a Docker image that runs as an isolated process on a host machine.

  8. In what real scenarios have you used Docker?

    • Docker is commonly used in software development, particularly in modern software development practices like DevOps and microservices architecture.

    • It allows for the deployment and scaling of applications in a consistent and portable way across different cloud platforms.

    • Additionally, Docker is often used in testing and continuous integration and delivery (CI/CD) workflows to automate the building, testing, and deployment of software applications

  9. Docker vs Hypervisor?

    • Docker runs applications in isolated containers, while Hypervisor creates virtual machines that run their operating systems.

    • Docker is typically more lightweight and efficient than Hypervisor.

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

  11. What is a Docker namespace?

    • Docker namespace is a way to separate and isolate resources (like processes and network interfaces) within a container.

    • It helps avoid conflicts between containers and ensures that each container runs independently.

  12. What is a Docker registry?

    • Docker Registry is a server that stores Docker images. It allows for sharing images with others or using them across multiple environments.

    • Docker Hub is a popular public registry for Docker images.

  13. What is an entry point?

    • The entry point is the command that specifies what executable should run when a container is started from a Docker image.

    • It is the default command that is executed when a container is started, and it can be configured in the Dockerfile or overridden at runtime with the docker run command.

  14. How to implement CI/CD in Docker?

    • Write your application's code and store it in a Git repository.

    • Create a Dockerfile that describes your application's environment and dependencies.

    • Use a CI/CD tool like GitLab CI/CD or GitHub Actions to automatically build, test, and push the Docker images to a registry.

    • Use a container orchestration tool like Kubernetes or Docker Swarm to manage and deploy the Docker containers in the production environment.

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

    • By default, any data written to a container's writable layer is deleted when the container exits.

    • However, you can use Docker volumes or bind mounts to persist data outside of the container's filesystem and prevent data loss.

  16. What is a Docker swarm?

    • Docker Swarm is a tool that allows you to manage multiple Docker hosts as a single cluster.

    • It helps you deploy and scale applications across those hosts, providing features such as load balancing and service discovery.

    • Swarm simplifies the deployment of containerized applications.

  17. What are the docker commands for the following:

    • view running containers --> docker ps / docker container ls

    • command to run the container under a specific name --> docker run --name my-container my-image

    • command to export a docker --> docker export my-container > my-container.tar

    • command to import an already existing docker image --> docker import my-image.tar my-image:tag

    • commands to delete a container --> docker rm <container_id/name>

    • command to remove all stopped containers, unused networks, build caches, and dangling images --> docker system prune / docker system prune --force

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

    To reduce the size of Docker images, common practices include using smaller base images, removing unnecessary files and dependencies, minimizing the number of layers, using Alpine-based images, and using a .dockerignore file.

Thank you so much for reading.

Follow me on LinkedIn to see interesting posts like this : )

Linkedin

Β