DevOps(Day-25) : Docker Interview Questions - Part1

 

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

    Image: Docker image is a read-only package containing necessary dependencies, and commands that can be executed to run an application. It is the prerequisite for creating a container.

    Container: It is the ability to package the application that has its own network, mounts and OS that can run anywhere, anytime and as many times as you want in any system.

    Engine: It is an open-source containerization for building and containerization of your application. It enables you to separate your applications from infrastructure which helps in faster delivery of the software.

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

    These both commands use to add a specific file from one location to another.

    COPY: This command copies the source code of the application from its original location to the path specified.

    ADD: It has the same functionality as COPY command but supports file compression and URL sources.

    The more secure way is COPY command. Therefore it is widely used.

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

    RUN: RUN executes when we build the image. That means the command passed to run executes on top of the current image in a new layer.

    CMD: With the cmd instruction, we can specify a default command that executes when the container is starting.

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

    When building a Docker image, you may want to make sure to keep it light. Avoiding large images speed up the build and deployment of containers and hence, it is critical to reduce the image size of images to a minimum.

    Here are some basic steps recommended to follow, which will help create smaller and more efficient Docker images.

    1. Use a smaller base image.

    2. Try to minimize the number of layers to install the packages in the Dockerfile.

    3. Utilize the Multi-Stage Builds Feature in Docker.

    4. Beware of Updates and Unnecessary Packages and Dependencies.

  5. Why and when to use Docker?

    Why? - Docker is used to containerising an application that can be run in any system with any configuration at any time.

    When? - Suppose there are two developers designed a build and one of them want to transfer the new version of applications to their teammate but now it doesnot work. This situation came due to the difference in the dependencies of the their systems. The only way to overcome the situation is by using containers which can be achieved by Docker.

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

    It is divided into three parts:-

    Docker Architecture in Detail - Whizlabs Blog

    1. Docker Client - Docker client uses commands and REST APIs to communicate with the Docker Daemon (Server). When a client runs any docker command on the docker client terminal, the client terminal sends these docker commands to the Docker daemon. Docker daemon receives these commands from the docker client in the form of command and REST API's request.

    2. Docker Host - Docker Host is used to provide an environment to execute and run applications. It contains the docker daemon, images, containers, networks, and storage.

    3. Docker Registry - Docker Registry manages and stores the Docker images.

      There are two types of registries in the Docker -

      Pubic Registry - Public Registry is also called as Docker hub.

      Private Registry - It is used to share images within the enterprise.

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

    Docker Compose - Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.

    Docker File - It is a simple text file with a set of commands or instructions. These commands/instructions are executed successively to perform actions on the base image to create a new docker image.

    Docker Image - Docker image is created when we run the Docker file. A Docker image is a file used to execute code in a Docker container. Docker images act as a set of instructions to build a Docker container, like a template. Docker images also act as the starting point when using Docker. An image is comparable to a snapshot in virtual machine (VM) environments.

    Docker Container - Docker containers are the live, running instances of Docker images. While Docker images are read-only files and executable content. Users can interact with them, and administrators can adjust their settings and conditions using Docker commands.

  8. In what real scenarios have you used Docker?

    I have used Docker to containerise an nginx application. I have written a Docker file including the base image and its dependencies. Thus resulting in building a container. This helped to push the image to the remote repository i.e. DockerHub This image now can be pulled anytime from the repo to run on any system and this reduced the time of building the application everytime for the project.

Comments

Popular posts from this blog

DevOps(Day-97): Meta-Arguments in Terraform

DevOps(Day-95): Auto Scaling with Terraform

DevOps (Day-1) Introduction