• +91 9723535972
  • info@interviewmaterial.com

Docker Interview Questions and Answers

Related Subjects

Docker Interview Questions and Answers

Question - 41 : - Explain the process of scaling your Docker containers

Answer - 41 : -

The Docker containers can be scaled to any level starting from a few hundred to even thousands or millions of containers. The only condition for this is that the containers need the memory and the OS at all times, and there should not be a constraint when the Docker is getting scaled.

Question - 42 : - What is the method for creating a Docker container?

Answer - 42 : -

You can use any of the specific Docker images for creating a Docker container using the below command.

docker run -t -i command name
This command not only creates the container but also start it for you.

Question - 43 : - Differentiate between COPY and ADD commands that are used in a Dockerfile?

Answer - 43 : -

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.

Question - 44 : - Can a container restart by itself?

Answer - 44 : -

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]

Question - 45 : - What is the purpose of the volume parameter in a docker run command?

Answer - 45 : -

1. The syntax of docker run when using the volumes is: docker run -v host_path:docker_path
2 . 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.
3. 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.

Question - 46 : - Where are docker volumes stored in docker?

Answer - 46 : -

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/

Question - 47 : - What does the docker info command do?

Answer - 47 : -

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.

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

Answer - 48 : -

  • 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 “attached” mode 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.

Question - 49 : - Can you tell the approach to login to the docker registry?

Answer - 49 : -

Using the docker login command credentials to log in to their own cloud repositories can be entered and accessed.

Question - 50 : - List the most commonly used instructions in Dockerfile?

Answer - 50 : -

  • 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.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners