Monday, December 3, 2018

Top 100 docker interview questions


Top 100 Docker Interview Questions

    
 The questions are divided into 6 domains as listed below :

  • Installation and Configuration 
  • Orchestration
  • Image Creation, Management, and Registry 
  • Networking 
  • Security 
  • Storage and Volumes 

Installation and Configuration 

Below are the related questions & answers :



Orchestration

Below are the related questions & answers :
Q.How to get rid of all non-running containers 
===========================================================
# docker rm $( docker ps -q )


Q. Scenario to find diff (changes in the container made & compared to the image )
[2.When to create a container ? Difference between Container and Image ?]
================================================================================
#docker run -it --name testdocker5 alpine ash
# mkdir testDir
# exit
# docker diff testdocker5

 o/p

# C /root
A /root/.ash_history
A /testDir

3.How to create an Image in Docker ?
=======================================
# Modify a new container
docker run --name my_container ubuntu:latest
   touch /HelloWorld

# Commit the changes you made in that container
# to a new image
docker commit my_container my_image

# Remove the changed container
docker rm -vf my_container

# Test the new image docker run --rm my_image
# ls -l /HelloWorld
# Outputs:
# -rw-r--r-- 1 root root 0 
# /HelloWorld


Q.A new feature of docker is now enabled, How to determine whether your docker CLI can handle it - ?
======================================================================================
Experimentail cli : USERFOLER\.docker\machine\machines\default
open config.json

mirror upgrade : docker-machine upgrade 


Q.when to use between Run , Pull and Exec options in Docker ?


Q.What is default port of docker daemon ?
======================================
$ docker-machine env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://14.354.34.100:2376"



Q.A Docker machine can talk to another Docker machine - As DevOps , What do you need ?
============================================================================
Through  overlay & by network Ingress

The overlay network driver creates a distributed network among multiple Docker daemon hosts. This network sits on top of (overlays) the host-specific networks, allowing containers connected to it (including swarm service containers) to communicate securely. Docker transparently handles routing of each packet to and from the correct Docker daemon host and the correct destination container.

When you initialize a swarm or join a Docker host to an existing swarm, two new networks are created on that Docker host:

an overlay network called ingress, which handles control and data traffic related to swarm services. When you create a swarm service and do not connect it to a user-defined overlay network, it connects to the ingress network by default.
a bridge network called docker_gwbridge, which connects the individual Docker daemon to the other daemons participating in the swarm.



Q.Docker Containers are persistent - Agree?
===========================================================
Yes , For every docker commit it is creating image 
https://thenewstack.io/methods-dealing-container-storage/


Q.Docker Containers - Can the same image be stored in different Containers - If yes , 
 what is the state of the image in Dockers , if there an option to state persistence?
==============================================================================
 yes


Q.How to identify the log of the container ?
===============================================
docker inspect testdocker5
o/p
  "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},




Q.Without Docker ps-a , is there an option to determine whether a container is in UP state 
========================================================================================
 docker container ls
 $ docker inspect -f "{{.Name}}{{.State.Status}}" testdocker5

 o/p
 /testdocker5exited

  $ docker inspect -f "{{.Name}}{{.State.Status}}} $(docker ps -q)
  
  $ docker inspect -f "{{.Name}}{{.State.Status}}" $(docker ps -a -q)

/testdocker5exited
/testcont2paused
/testubn1running
/sampletestcontainerexited


docker run -dit  --name testubn3 ubuntu bash
docker attache testubn3
exit



12.When Pulling the Image from HUB Docker - What is the First protocol Docker server checks
===========================================
docker info


Q.Is each Docker-machine a VM ? 
=====================================
boot to docker
C:\Users\sjyetki.ORADEV\.docker\machine\machines\default
+CLI



Q.Can docker machine be associated with vairous docker drivers like hyperv, virtualbox?
===========================================================
Only one at a time


Q.Hypervisor - is Docker a replacement for Hypervisor ?
===========================================================
No , Docker brings additional services on top of Hypervisor



@.Is Docker a Freeware?
===========================================================
No 



Q.What is command to measure utilization of the Docker engine ?
===========================================================
#docker run -dit  --name test1 ubuntu bash
#docker stats test1
#docker top test1

Q.Dockers and VM - Do they co-exist ?
===========================================================
Yes

Q.container ID - What is length of Container ID ?
===========================================================
64 bytes


Q.Can an Image be overwritten in Docker ? 
===========================================================
yes


Q. Which objects have IPs in Docker ?
===========================================================
8 objects : HOST , MACHINE , Repository , container , volume , image , registry , network 


Q. What is default log driver of container ?
===========================================================
JSON



Q. How to determine the size of the running container?
===========================================================
#DIFFPATH="/var/lib/docker/aufs/diff"; \
(for d in `docker ps -q`; do du -s ${DIFFPATH}/${d}*; done;) | \
sed -e 's/-init//g' | \
awk '{ sum[$2] += $1 }; END { for (path in sum) { print sum[path]/1024"M", path } }'


Q. To delete all containers in a single step ?
===========================================================
#docker rm $( docker ps -a )













Image Creation, Management, and Registry Networking 

Below are the related questions & answers :

Security 

Below are the related questions & answers :

Storage and Volumes 

Below are the related questions & answers :



Tuesday, November 27, 2018

Docker Quick-Start

                             
 DOCKER QUICK-START 


What is DOCKER ?

Docker is the latest buzz in the IT world & people really need to know this . Lets start then : 
Docker is a containerization platform which packages an application & all its dependencies into a container. Docker is a tool designed to make it easier to create, deploy, and run applications by using containers.
Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. Create self-contained development environments inside Docker containers. So, we share an environment already configured. The principal is “Build once deploy anywhere “
Activating this container results in the application being active.
This container we are talking about is light-weight, easily deployable, and transportable.

But why the madness behind Docker?

Because implementing any application in the traditional way using a VM is a pain. Why is it a pain?
Because each of these VMs:
·       Consume a lot of memory resources from the host
·       Are slow and take a lot of time to boot
·       Block even unused resource from the host
·       Increase the architecture complexity, as the no of VMs increase

Why Docker

·       It’s a simple and intuitive tool.
·       It enables you to spend less time on configuration and more time on building software.
·      It will allow you to build up independent containers that will interact with each other seamlessly with accuracy and speed.
·       It is a fast and consistent way to accelerate and automate the shipping of software.
·       It saves developers from having to set up and configure multiple development environments each time they test or deploy

Virtual Machines Vs Container 

We can clearly see why docker is a clear winner 


 Virtual Machines


Virtualization is the technique of importing a Guest operating system on top of a Host operating system. This technique was a revelation at the beginning because it allowed developers to run multiple operating systems in different virtual machines all running on the same host. This eliminated the need for extra hardware resource. The advantages of Virtual Machines or Virtualization are:
·       Multiple operating systems can run on the same machine
·       Maintenance and Recovery were easy in case of failure conditions
·       Total cost of ownership was also less due to the reduced need for infrastructure

Virtualization also has some shortcomings. Running multiple Virtual Machines in the same host operating system leads to performance degradation. This is because of the guest OS running on top of the host OS, which will have its own kernel and set of libraries and dependencies. This takes up a large chunk of system resources, i.e. hard disk, processor and especially RAM. 
Another problem with Virtual Machines which uses virtualization is that it takes almost a minute to boot-up. This is very critical in case of real-time applications.
Following are the disadvantages of Virtualization:
·       Running multiple Virtual Machines leads to unstable performance
·       Hypervisors are not as efficient as the host operating system
·       Boot up process is long and takes time



Containers

Containerization is the technique of bringing virtualization to the operating system level. While Virtualization brings abstraction to the hardware, Containerization brings abstraction to the operating system. Do note that Containerization is also a type of Virtualization. Containerization is however more efficient because there is no guest OS here and utilizes a host’s operating system, share relevant libraries & resources as and when needed unlike virtual machines. Application specific binaries and libraries of containers run on the host kernel, which makes processing and execution very fast. Even booting-up a container takes only a fraction of a second. Because all the containers share, host operating system and holds only the application related binaries & libraries. They are lightweight and faster than Virtual Machines.
Advantages of Containerization over Virtualization:
  • Containers on the same OS kernel are lighter and smaller
  • Better resource utilization compared to VMs
  • Boot-up process is short and takes few seconds
  • They are faster and lighter to ship as they house the minimum requirements to run your application
  • They can be versioned, shared, and archived
  • They are instantly started as they carry a much smaller blueprint than Virtual Machines
  • Build configurations are managed with declarative code
  • They can be built and extended on top of pre-existing containers





Docker Architecture


The basic architecture of Docker consists of 3 major parts:
  1.  Docker Host
  2.  Docker Client
  3.  Registry


Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of the building, running, and distributing your Docker containers.
The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface.


The Docker Host

Docker Host runs the Docker Daemon. Docker Daemon listens for Docker requests.
Docker requests could be ‘docker run’, ‘docker build’, anything.
It manages docker objects such as images, containers, networks, and volumes.

The Docker Client

 Docker Client is used to trigger Docker commands. When we send any command (docker build, docker run, etc) the docker client ends these commands to Docker daemon which further will deal with them.
Note: The Docker client can communicate with more than one daemon.

Docker Registries 

The Registry is a stateless, highly scalable server-side application that stores and lets you distribute Docker images. You can create your own image or you can use public registries namely, Docker Hub and Docker Cloud. Docker is configured to look for images on Docker Hub by default.

We can create our own registry in fact.So, when we run the command docker pull or docker run, the required images are pulled from your configured registry. When you use the docker push command, your image is pushed to your configured registry.

Top 100 docker interview questions

T op 100 Docker Interview Questions       The questions are divided into 6 domains as listed below : Installation and Configuratio...