Most frequently asked Docker Interview Questions and Answers for Fresher
1. What is Docker?
Docker is a new form of Software Containerization in the field of IT. It is an open-source container service designed to facilitate applications deployment inside the software containers. It relies on Linux Kernel Features such as namespaces and cgroups ensuring that resource isolation and application packaging along with its dependencies.
was licensed under Apache License 2.0 in the binary form and wholly written in the Go programming language. It supports several operating systems such as Linux, Cloud, Windows, and Mac OS and different platforms such as ARM architecture and x86-64 windows platforms.
2. Why use Docker?
- A user can quickly build, ship, and run its applications.
- A single operating system kernel runs all containers.
- Docker container is more light-weight than the virtual machines.
- A user can deploy Docker containers anywhere, on any physical and virtual machines and even on the cloud.
3. What are the components of Docker Architecture?
Docker Client (docker )
enables a user for Docker interaction. It can communicate with more than one Docker Daemon. It uses Docker API and sends command ( docker run)
to Docker Daemon ( dockerd )
which carries them out.
Docker Daemon ( dockerd )
gives a complete environment to execute and run applications. It consists of images, containers, volumes and responsible for all container-related actions. It pulls and creates the container images as what the client requests. A Daemon can communicate with other daemons for its service management.
is versioning, storage, and distribution system for Docker images. It allows Docker users to pull images locally, as well as push new images to the registry. Docker Hub
is a public registry instance of Docker used by default while installing Docker Engine.
is a lightweight, standalone, executable package of Docker stored in a Docker Registry. It is used to create a container. It consists of everything needed to run an application- code, a runtime, system libraries, system tools, environment variables, configuring files, and settings.
is a standardized unit of software used to deploy a particular application or environment. It launched by running an image. It packages up code and all of its dependencies so that apps can run quickly and reliably from one computing environment to another.
4. On what platforms does Docker run?
Docker runs on various platforms as follows:
- Ubuntu 12.04, 13.04 et al
- Fedora 19/20+
- RHEL 6.5+
- CentOS 6+
- openSUSE 12.3+
- CRUX 3.0+
- Windows Server 2016
- Windows 10
- Amazon EC2
- Google Compute Engine
- Microsoft Azure
5. What is Docker Engine?
is a Client-Server application installed on the host machine. It allows you to develop, assemble, ship, and run applications anywhere. It is available for Linux or Windows Server. Its major components are as follows:
- Server is a long-running program called a Daemon process (docker )
- REST API specifies interfaces that docker uses to communicate with Daemon and instruct it what to do.
- CLI (Command Line Interface) uses the Docker REST API to manage and interact with the Daemon through its scripting commands.
6. What is the Lifecycle of Docker container?
The Lifecycle of Docker Container with CLI is below:
- Create a Container.
- Run the created Container.
- Pause the processes running inside the Container.
- Unpause the processes running inside the Container.
- Start the Container, if exists in a stopped state.
- Stop the Container as well as the running processes.
- Restart the Container as well as the running processes.
- Kill the running Container.
- Destroy the Container, only if it exists in a stopped state.
7. List the most used commands of Docker.
- ps lists the running containers.
- dockerd launches Docker Daemon.
- build is used to build an image from a DockerFile.
- create is used to create a new image form container’s changes.
- pull is used to download a specific image or a repository.
- run is used to run a container.
- logs display the logs of a container.
- rm removes one or more containers.
- rmi removes one or more images.
- stop is used to stop one or more container.
- kill is used to kill all running containers.
8. Does the data get lost, if the Docker container exits?
No. any data that our application writes to disk gets well preserved in its container until we explicitly delete the container and the file system persists even after the container halts.
9. What is Dockerfile and its use?
DockerFile is a text document used to assemble a Docker image. It consists of a list of Docker commands and operating system commands for building an image. These commands execute automatically in sequence in the Docker environment and create a new Docker image.
10. How Docker is advantageous over Hypervisors?
Docker is advantageous. It is lightweight and more efficient in terms of resources as it uses very fewer resources and also the underlying host kernel rather than developing its hypervisor.
11. How to create a Docker container?
A Docker Container gets created by running any specific Docker image.
Use the following command to create a container as this command creates and starts the container.
docker run -t -i command name
If to verify that whether the container has created or whether that is running or not, use the following command as this command lists out all the running Docker containers on the host along with their status.
docker ps -a
12. Can json be used instead of yaml for compose file?
Yes, json can be used instead of yaml for compose file such that you have to specify the file name with the following command:
docker-compose -f docker-compose.json up