Docker



1. What is Docker?  

Short Answer

Docker is a platform to run each application isolated and securely. Internally it achieves it by using kernel containerization feature.

Long Answer

Docker is an open-source project that automates the deployment of Linux applications inside software containers. Quote of features from Docker web pages:

Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries – anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.

Docker provides an additional layer of abstraction and automation of operating-system-level virtualization on Linux. Docker uses the resource isolation features of the Linux kernel such as cgroups and kernel namespaces, and a union-capable file system such as aufs and others to allow independent "containers" to run within a single Linux instance, avoiding the overhead of starting and maintaining virtual machines.

The Linux kernel's support for namespaces mostly isolates an application's view of the operating environment, including process trees, network, user IDs and mounted file systems, while the kernel's cgroups provide resource limiting, including the CPU, memory, block I/O and network. Since version 0.9, Docker includes the libcontainer library as its own way to directly use virtualization facilities provided by the Linux kernel, in addition to using abstracted virtualization interfaces via libvirt, LXC (Linux Containers) and systemd-nspawn.



2. What is Docker Container?  

Short Answer

Docker Container is the instantiation of docker image. In other words, it is the run time instance of images. Images are set of files whereas containers is the one who run the image inside isolated.

Long Answer

In addition, Docker containers offer various advantages over virtual machines:
  • A hypervisor is required to host and maintain virtual machines; a system administrator needs to maintain the hypervisor itself. However, the Docker engine is a lightweight container virtualization technology that runs on the host operating system, and Docker containers can be started very quickly. Thus, the Docker technology alleviates the efforts of system administrators.
  • Although virtual machines and Docker containers both offer resource isolation, Docker containers share the operating system’s kernel and appropriate bins or libraries with other Docker containers. The result is faster deployment, less overhead, easier migration, and faster restarts.
  • Docker containers are imported into the Docker engine as simple .tar files, enabling Docker containers to spin up and down very quickly. The Docker engine handles virtualization parameters such as allocation of the file system when the application is launched. To successfully run an application on a virtual machine, the hypervisor needs to first import the virtual machine and then power it up; this takes time.


3. How is Docker different from other container technologies?  

Well, Docker is a quite fresh project. It was created in the Era of Cloud, so a lot of things are done much nicer than in other container technologies. Team behind Docker looks to be full of enthusiasm, which is of course very good.I am not going to list all the features of Docker here but i will mention those which are important to me.

Docker can run on any infrastructure, you can run docker on your laptop or you can run it in the cloud.

Docker has a Container HUB, it is basically a repository of containers which you can download and use. You can even share containers with your applications.

Docker is quite well documented.


4. What is the advantage of Docker over hypervisors?  

Docker is light weight and more efficient in terms of resource uses because it uses the host underlying kernel rather than creating its own hypervisor.




5. Is Container technology new?  

No, it is not. Different variations of containers technology were out there in *NIX world for a long time.Examples are:- Solaris container (aka Solaris Zones),FreeBSD Jails,AIX Workload Partitions (aka WPARs),Linux OpenVZ



6. What is Docker Image?  

Docker Image is the source of the docker container.In other words,docker images are used to create containers.It is possible create multiple isolated containers from a single image.



7. Difference between Docker Image and container?  

Docker container is the runtime 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.



8. What is the use case for Docker?  

Well, I think, docker is extremely useful in development environments. Especially for testing purposes. You can deploy and re-deploy apps in a blink of eye.

Also, I believe there are use cases where you can use Docker in production. Imagine you have some Node.js application providing some services on web. Do you really need to run full OS for this?

Eventually, if docker is good or not should be decided on an application basis. For some apps it can be sufficient, for others not.



9. How do you create docker image?  

Docker image are created using Docker file.Docker build is command to create docker image out of docker file.



10. You have the docker image,What is the next step?  

With docker image,we can spawn as many containers as needed.All containers can be same instance or it can also be different instance,what I mean that if we are using the same command for creating multiple containers,all container will behave as same.However,if you choose different command to create container out of same image,it will provide different functionality altogether.



11. How to create docker container?  

We can create docker container by running this command

docker run -t-i <image name> <command name>

This will create and start the container.



12. How to know the container status?  

Just fire docker ps -a to list out all running container with status (running or stopped) on a host.



13. How to stop and restart the containers?  

To stop container,we can use docker stop <container id>

To start a stopped container,docker start <container id> is the command

To restart a running container,docker restart <container id>



14. How did you become involved with the Docker project?  

I came across Docker not long after Solomon open sourced it. I knew a bit about LXC and containers (a past life includes working on Solaris Zones and LPAR on IBM hardware too), and so I decided to try it out. I was blown away by how easy it was to use. My prior interactions with containers had left me with the feeling they were complex creatures that needed a lot of tuning and nurturing. Docker just worked out of the box. Once I saw that and then saw the CI/CD-centric workflow that Docker was building on top I was sold.



15. Docker is the new craze in virtualization and cloud computing.Why are people so excited about it?  

I think it’s the lightweight nature of Docker combined with the workflow. It’s fast, easy to use and a developer-centric DevOps-ish tool. Its mission is basically: make it easy to package and ship code. Developers want tools that abstract away a lot of the details of that process. They just want to see their code working. That leads to all sorts of conflicts with SysAdmins when code is shipped around and turns out not to work somewhere other than the developer’s environment. Docker turns to work around that by making your code as portable as possible and making that portability user friendly and simple.



16. What,in your opinion,is the most exciting potential use for Docker?  

It’s definitely the build pipeline. I mean I see a lot of folks doing hyper-scaling with containers, indeed you can get a lot of containers on a host and they are blindingly fast. But that doesn’t excite me as much as people using it to automate their dev-test-build pipeline.



17. How is Docker different from standard virtualization?  

Docker is operating system level virtualization. Unlike hypervisor virtualization, where virtual machines run on physical hardware via an intermediation layer (“the hypervisor”), containers instead run user space on top of an operating system’s kernel. That makes them very lightweight and very fast.



18. What’s the difference between up,run, and start?  

Typically, you want docker-compose up. Use up to start or restart all the services defined in a docker-compose.yml. In the default “attached” mode, you’ll see all the logs from all the containers. In “detached” mode (-d), Compose exits after starting the containers, but the containers continue to run in the background.

The docker-compose run command is for running “one-off” or “adhoc” tasks. It requires the service name you want to run and only starts containers for services that the running service depends on. Use run to run tests or perform an administrative task such as removing or adding data to a data volume container. The run command acts like docker run -ti in that it opens an interactive terminal to the container and returns an exit status matching the exit status of the process in the container.

The docker-compose start command is useful only to restart containers that were previously created, but were stopped. It never creates new containers.



19. Can I use json instead of yaml for my Compose file?  

Yes, Yaml is a superset of json so any JSON file should be valid Yaml. To use a JSON file with Compose, specify the filename to use, for example:

docker-compose -f docker-compose.json up


20. Should I include my code with COPY/ADD or a volume?  

You can add your code to the image using COPY or ADD directive in a Dockerfile. This is useful if you need to relocate your code along with the Docker image, for example when you’re sending code to another environment (production, CI, etc).

You should use a volume if you want to make changes to your code and see them reflected immediately, for example when you’re developing code and your server supports hot code reloading or live-reload.

There may be cases where you’ll want to use both. You can have the image include the code using a COPY, and use a volume in your Compose file to include the code from the host during development. The volume overrides the directory contents of the image.



Java Interview Question

.Net Interview Question

PHP Interview Question

AngularJS Interview Questions