Docker interview questions

 Q1 what is docker?

ans it is mechanism which is used to create containers. containers are isolated environment to run your application.


Q what is the advantage of Docker over hypervisors?

 Docker containers use docker-engine instead of the hypervisor, like in virtual machines. As the host kernel in not shared, using docker-engine makes containers small, isolated, compatible, high performance-intensive and quickly responsive.


Q what is docker images?

Ans it is snapshot of base image. It combination of code and base machine library files.

it does not have stages like running or stop, exit and paused


Q what is docker container?

ans it is running instance of docker image.

it does have stages like running and stop, exit, paused.


Q what is docker hub?

ans it is registary where you can download mulitple images. 


Q how to create docker container?

docker run -it image shell


Q how many container can run per host?

there is no such limit. it is totally depend on hardware capability.


Q is container technology new?

no it is growing technology


Q what are network that are available by default?

there are three type of network

a) bridge - it is default network all containers connect to if you dont specify  the network yourself.

b) none - connects to a container specific network stock that locks a  network interface.

if you are running your container just for testing purpose then you can select 'none'

c) host - connects to the host's network stack - there will be no isolation between the host machine and the container, as far as network is concerned.

(host network will be utilized to get in touch with your docker container.)



Q difference between docker images and docker container

Ans docker images is snapshot of base machine or configuration files or code where in container is running state of your docker image.

(docker container is running instance of docker image.)

(docker image does not have a state, and its state never changes as it is just set of files whereas docker container has its execution state)


Q what is diff b/w docker and VM?

VM === Server>Host OS> Hypervisior> Guest OS > Binaries/Libs > YOUR APP

Docker === Server > Host OS > Docker Engine > Bin/Libs > Your APP 


Q why do my services take 10 seconds to recreate or stop?

when we configure docker engine then we have to define default time. whenever container is running we have to give some time that container can stop or accessing new connection. default time is set 10 sec. we can forcefully increase or decrease this time.


Q how do i run multiple copies of a compose file on the same host?

custome project name using the -p command line option or the COMPOSE_PROJECT_NAME environment variable.


Q can i user json instead of yaml for my compose file?

yes you can use both json as well as yaml

docker-compose -f docker-compose.json up


Q should I include my code with COPY/ADD or a volume?

OR

Q what is difference between ADD and COPY in Dockerfile?

copy - it is used for copy files from local machine.

add - it is used for copy files from remote location so we use url to copy the data.


if you add volume afterwards copy and add the it will overwrite copy/add command.


Q how do you save docker image?

docker save -o image.tar.gz container-tag


Q how to load your docker image

Docker load 


=================2nd part=====================


Q 1 what is docker compose?

Ans wherein you need to run multiple container as single component

for example you have application where you need to use database, webserver. you need to mount volume as well so

docker compose is a file which contains information about different images, all the services you are going to run, which network it is going to use, what all volume will be mounted, which containers 

so these sort of command docker compose files contains.


Docker compose is a file which let you run multiple container as single services.

when you use docker compose up or down command to make all the container up and down with single command. 


Q 2 what is docker swarm?

docker swarm is utility for docker orchestation.

for example you want to run 10 containers.

currently you are running only one containers or you want to increase number of containers with same code and same image so you can manage this sort of thing with the help of docker swarm command. 

It is by default available when you install docker. so you need to run command 

docker swarm init (it will start the docker swarm utility in the docker)


Q what is docker Namespace?

namespace is concept which lets you run container in all isolated environment 

it is feature of linux operating system it provides isolation base on user, hard drive, hostname , network , inter process communication and process.

it is isolating resources per process or group.


what is cgroups


it let you put limition on usage of resources. it limit amount of resources used per process. 


Q what is the lifecycle of docker container?

there are mulitple state of docker container

- create a container 

- run the container

- pause teh container(optional)

- unpause the container (optional)

- start the container

- stop the container

- restart the container

- kill the container

- destroy the container


Q what is docker machine?

Ans

docker machine lets you manage you docker container in fact docker machine lets you manage the state of docker container.


Q how to check for docker client and docker server version?

and docker version


Q how do you get the number of containers running, paused and stopped?

docker info


Q how to login into docker repository?

docker login


Q how do you create a docker container from an image?

ans docker run -it -d image_name


Q how do you list all the running containers

docker ps


Q suppose you have 3 container running and out of these, you wish to access on of them. how do you access a running container?

docker exec -it <container id> sh


Q how to start,stop and kill the container?

docker start container id

docker stop container id

docker kill container id


Q how do you push it to docker hub?

docker push username/image name


Q how to delete a stopped container?

docker rm container id


Q how to delete a container without stopping it?

docker rm -f container id


Q how to delete an image from the local storage system?

docker rmi image-id


Q how to build an image from Dockerfile?

docker build dockerfile path


Q do you know why docker system prune is used? what does it do?

docker system prune is used to remove all stopped containers


Q will you lose your data, when a docker container exists?

No

untill unless you remove your container forcefully, data will not be removed.


Q can a container restart by itself?

No

bydefault the flag -restart is set to false.


Q is it better to directly remove the container using the rm command or stop the container followed by remove container?

if you remove the container forcefully then all the existing connection will be terminated forcefully

if you first stop the container then remove it . it will clear the existing connection first then remove it.


Q is it good practice to run stateful applications on Docker?

no

all the stateful application preferred to put data on the local host drive. If you need to migrate your system from one instance to another then it is really hard to retrive data from multiple docker container running. If you application is stateless then it is good to go with docker container.



====================================part3========================================================


Q what is docker registry?

Docker cloud and docker hub are the public registries where these images can be hosted upon.


Qwhat are docker objects?

docker objects are docker images, services and docker containers


Q can you tell reasons why container networking is so important?

- containers need to talk to external world.

- reach containers from external world to use the service that container provides.

- allows containers to talk to host machine.

- inter-container connectivity in same host and across hosts.

- discover services provided by containers automatically.

- load balance traffic between different containers in a service.

- provide secure multi-tenant services.


Q how to create a user-defined bridge network?

docker network create your_nw_name


Qhow is overlay network different from bridge network?

bridge works on single host overlay supports among multiple server connectivity.

 

Q what networks are affected when you join a docker host to an existing swarm?

first of all your overlay will be impacted then it will impact bridge one.


Qhow shall you disable the networking stack on a container? means if you want to run docker container without network.


#docker run -it --network none alpine /bin/sh


Qhow to check details of network in a docker container?

docker inspect container_id


Qwhat is docker swarm?


Q can you explain different volume mount types available in docker?

Volumes are stored in a part of the host filesystem which is managed by Docker(/var/lib/docker/volumes/ on Linux

Bind mounts may be stored anywhere on the host system.

Tmpfs mounts are stored in the host system's memory only, and are never written to the host system's filesystem.



Q what is role of .dockerignore file?

it is just like .gitignore file 

for ex. you have a file Dockerfile in same directory where you have multiple other files as  well but do not want that when your docker image will be created you are going to use copy command or add command then you do not want all the file to be added inside the docker container. it may same use case of .gitignorefile.


Q what is the purpose of EXPOSE command in Dockerfile?

this is used for port mapping between docker host and docker container.


Q how is ENTRYPOINT instruction under Dockerfile different from CMD instruction?

ans 

FROM Alpine

CMD ["/etc/passwd","/etc/shadow"]   -- it provided arguments like file name

ENTRYPOINT["cat"}   - it provide command like cat or cd 


Q why build cache in docker is so important.

if objects are not changed between two builds of docker container image, docker can use build cache with becomes times saver at the time of building image.



Q what are the most common instructions in Dockerfile?

FROM alpine

MAINTAINER Server Ryan

LABEL: "Application_Environment"="Development"

RUN yum update && yum -y install httpd

RUN mkdir -p /data/servergyan

WORKDIR /data/myscript

CMD python app.py

EXPOSE 80 443

EXPOSE 80/tcp 8080/udp

ADD /root/testfile /data/

COPY..

ENTRYPOINT ping google.com

VOLUME /appdata:/appdata

USER instruction is used to set the username,groupname, UID and GID for running subsequent commands.

Else root user will be used.

ENV APP_DIR /data/

ARG TMP_NAME mycustom_image

ONBUILD RUN yum install httpd


Q what is state-full vs stateless application?

A stateless app is an application program that does not save client data generated in one session for use in the next session with that client. 


if you are accessing your facebook, if facebook stores your data which you have generated within the session and that will be use in next session as well then that will be stateless

if it is statefull that does not hold data that can be used in next session


What is Stateful?

To understand what the word Stateful refers to, let us look at an analogy. Consider the scenario of a telephone call. In this case, the connection is maintained from the beginning to the end of the call to ensure continuous communication. The connection is validated first, and only then will the session be established indefinitely until the end of the talk. This is exactly what a stateful protocol is. If a client delivers a request to the server in a stateful protocol, it expects a response of some sort. If it does not receive a response, it will send the request again.


However, the major feature of stateful is that it maintains the state of all its sessions, be it an authentication session, or a client’s request for information. Stateful are those that may be used repeatedly, such as online banking or email. They’re carried out in the context of prior transactions in which the states are stored, and what happened in previous transactions may have an impact on the current transaction. Because of this, stateful apps use the same servers every time they perform a user request. An example of stateful is FTP (File Transfer Protocol). For the course of an FTP session, which often includes many data transfers, the client establishes a Control Connection. After this, the data transfer takes place.



What is Stateless?

In order to comprehend what Stateless means, let us consider a scenario just like we did in the case of Stateful. Consider the event of sending an SMS. Here, the receiver’s availability is not confirmed, and the sender just sends the SMS to the recipient. There is no confirmation from the receiving device to the sending device that the message has been received. Despite being transmitted, the communication may or may not be received. There can be no cross-verification of status or retries. This is what stateless is all about.


A stateless protocol is one in which the receiver is not required to keep session state from previous requests. The sender sends relevant session state to the receiver in such a way that each request may be interpreted without reference to prior requests’ session state, which the receiver retains. HTTP (HyperText Transfer Protocol) is an example of Stateless Protocol because each request is executed independently of the requests that came before it. This implies that once a transaction is completed, the connection between the browser and the server is also terminated.



Q what is meaning of container runtime and how many types run-time are available for container.

ans 

Container runtimes focus more on running containers, setting up namespace and cgroups for containers, and are also called lower-level container runtimes. Higher-level container runtimes or container engines focus on formats, unpacking, management, and image-sharing. They also provide APIs for developers.



There are three main types of container runtimes—low-level runtimes, high-level runtimes, and sandboxed or virtualized runtimes.

=================================================

devops


what have you been doing over the last 1-2 years?

or what new did you learn in last 2 years? docker container, azure, kubernetes, linux

AWS,Docker, Jenkins, JIRA, Linux


Q how do you deploy software? OR

What tool to you use to deploy code? if aws - code deploy.

opensource - jenkins

partial paid and free - circle CI



Qhow have you handled failed deployments OR

how do you get notification for any failed deployment?

















Comments

Popular posts from this blog

GIT - 3

Docker - 6

GIT - 1