Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Can you tell the difference between CMD and ENTRYPOINT?

Answer»
  • CMD command provides executable defaults for an executing container. In case the executable has to be omitted then the usage of ENTRYPOINT INSTRUCTION along with the JSON array FORMAT has to be incorporated.
  • ENTRYPOINT specifies that the instruction within it will always be run when the container starts. 
    This command provides an option to configure the parameters and the executables. If the DockerFile does not have this command, then it would STILL get inherited from the base IMAGE mentioned in the FROM instruction.
    - The most commonly used ENTRYPOINT is /bin/sh or /bin/bash for most of the base images.
  • As part of good practices, every DockerFile should have at least one of these TWO commands.
2.

What is the best way of deleting a container?

Answer»

We NEED to follow the following two steps for deleting a CONTAINER:
- DOCKER stop <container_id>
- docker RM <container_id>

3.

What is the way to establish communication between docker host and Linux host?

Answer»

This can be done using networking by IDENTIFYING the “ipconfig” on the docker HOST. This COMMAND ensures that an ethernet adapter is created as LONG as the docker is present in the host.

4.

Can you differentiate between Daemon Logging and Container Logging?

Answer»
  • In DOCKER, logging is supported at 2 levels and they are logging at the Daemon level or logging at the Container level.
  • Daemon Level: This KIND of logging has four levels- Debug, Info, Error, and Fatal.
    - Debug has all the data that happened during the execution of the daemon process.
    - Info carries all the information along with the error information during the execution of the daemon process.
    - Errors have those errors that occurred during the execution of the daemon process.
    - Fatal has the fatal errors that occurred during the execution.
  • Container Level:
    - Container level logging can be done using the command: SUDO docker run –it &LT;container_name> /bin/bash
    - In ORDER to check for the container level logs, we can run the command: sudo docker logs <container_id>
5.

List the most commonly used instructions in Dockerfile?

Answer»
  • FROM: This is used to set the base image for upcoming instructions. A docker file is considered to be valid if it starts with the FROM instruction.
  • LABEL: This is used for the image ORGANIZATION based on projects, modules, or licensing. It also helps in automation as we specify a key-value pair while DEFINING a label that can be later accessed and handled programmatically.
  • RUN: This command is used to execute instructions following it on the top of the CURRENT image in a NEW layer. Note that with each RUN command execution, we add layers on top of the image and then use that in SUBSEQUENT steps.
  • CMD: This command is used to provide default values of an executing container. In cases of multiple CMD commands the last instruction would be considered.
6.

Can you tell the approach to login to the docker registry?

Answer»

USING the DOCKER login command CREDENTIALS to log in to their own cloud repositories can be entered and ACCESSED.

7.

What are the basic requirements for the docker to run on any system?

Answer»

Docker can run on both Windows and Linux platforms.

  • For the Windows platform, docker atleast needs Windows 10 64BIT with 2GB RAM space. For the LOWER versions, docker can be INSTALLED by taking help of the toolbox. Docker can be downloaded from https://docs.docker.com/docker-for-windows/ website.
  • For Linux platforms, Docker can run on various Linux flavors such as Ubuntu >=12.04, Fedora >=19, RHEL >=6.5, CentOS >=6 etc.
8.

Can you tell the what are the purposes of up, run, and start commands of docker compose?

Answer»
  • Using the up command for keeping a docker-compose up (ideally at all times), we can start or restart all the networks, services, and drivers associated with the APP that are specified in the docker-compose.yml file. Now if we are running the docker-compose up in the “ATTACHEDMODE then all the logs from the containers would be accessible to us. In CASE the docker-compose is run in the “detached” mode, then once the containers are started, it just exits and SHOWS no logs.
  • Using the run command, the docker-compose can run one-off or ad-hoc tasks based on the business requirements. Here, the service name has to be provided and the docker starts only that specific service and also the other services to which the target service is dependent (if any).
    - This command is helpful for testing the containers and also performing tasks such as adding or removing data to the container volumes etc.
  • Using the start command, only those containers can be restarted which were already created and then stopped. This is not useful for creating new containers on its own.
9.

What does the docker info command do?

Answer»

The command gets DETAILED INFORMATION about DOCKER installed on the host system. The information can be like what is the number of containers or IMAGES and in what state they are running and hardware specifications like total memory allocated, speed of the processor, kernel version, ETC.

10.

Where are docker volumes stored in docker?

Answer»

VOLUMES are created and managed by Docker and cannot be ACCESSED by non-docker entities. They are STORED in Docker host filesystem at /var/lib/docker/volumes/

11.

What is the purpose of the volume parameter in a docker run command?

Answer»
  • The syntax of docker run when using the volumes is: docker run -v host_path:docker_path <container_name>
  • The volume parameter is used for syncing a directory of a container with any of the host DIRECTORIES. Consider the below command as an example: docker run -v /data/app:usr/src/app myapp
    The above command mounts the directory  /data/app in the host to the usr/src/app directory. We can sync the container with the data files from the host without having the need to RESTART it.
  • This also ensures data security in cases of container deletion. This ensures that even if the container is deleted, the data of the container exists in the volume mapped host LOCATION making it the easiest WAY to STORE the container data.
12.

Can you tell the differences between a docker Image and Layer?

Answer»

Image: This is built up from a series of read-only layers of instructions. An image corresponds to the docker container and is used for speedy OPERATION due to the caching MECHANISM of each step.

Layer: Each layer corresponds to an instruction of the image’s Dockerfile. In simple words, the layer is also an image but it is the image of the instructions run.

Consider the EXAMPLE Dockerfile below.
FROM ubuntu:18.04 COPY . /myapp RUN make /myapp CMD python /myapp/app.py Importantly, each layer is only a set of DIFFERENCES from the layer before it. 

- The result of building this docker file is an image. Whereas the instructions present in this file add the layers to the image. The layers can be thought of as INTERMEDIATE images. In the example above, there are 4 instructions, hence 4 layers are added to the resultant image.

13.

Can a container restart by itself?

Answer»
  • Yes, it is possible only while using certain DOCKER-defined policies while using the docker run command. Following are the AVAILABLE policies:

    1. Off: In this, the container won’t be restarted in case it's stopped or it fails.
    2. On-failure: Here, the container restarts by itself only when it EXPERIENCES failures not ASSOCIATED with the user.
    3. Unless-stopped: Using this policy, ensures that a container can restart only when the command is EXECUTED to stop it by the user.
    4. Always: Irrespective of the failure or stopping, the container always gets restarted in this type of policy.

    These policies can be used as:
    docker run -dit — restart [restart-policy-value] [container_name]
14.

Differentiate between COPY and ADD commands that are used in a Dockerfile?

Answer»

Both the commands have similar functionality, but COPY is more preferred because of its HIGHER transparency level than that of ADD.
COPY provides just the basic support of copying local files into the container whereas ADD provides additional FEATURES like remote URL and tar EXTRACTION support.

15.

Differentiate between virtualization and containerization.

Answer»

The question INDIRECTLY translates to explaining the difference between virtual MACHINES and Docker containers.

Virtualization Containerization
This helps developers to run and host multiple OS on the hardware of a single physical server.This helps developers to deploy multiple applications using the same operating system on a single virtual machine or server.
Hypervisors provide overall virtual machines to the guest operating SYSTEMSContainers ensure isolated environment/ user spaces are PROVIDED for running the applications. Any changes done within the container do not REFLECT on the host or other containers of the same host.
These virtual machines form an abstraction of the system hardware layer this means that each virtual machine on the host acts like a physical machine.Containers form abstraction of the application layer which means that each container constitutes a different application.