Day 21 - Docker Interview Questions

What is the Difference between an Image, Container and Engine?
Image is like a complete package that has everything needed to run a piece of software. It includes the code of the software, the environment in which it runs, the necessary libraries, and any other dependencies it requires.
Container is a lightweight, isolated, and self-contained runtime environment that encapsulates an application and its dependencies. It provides a standardized way to package software, along with all the necessary files, libraries, and configurations needed to run it.
Containers are created from container images, which are essentially snapshots or templates of a specific application or service. These images contain all the necessary files and instructions to create and configure the container.
In the context of containerization, the term "engine" typically refers to a container engine or container runtime. A container engine is the underlying software responsible for the creation, management, and execution of containers.
What is the Difference between the Docker command COPY vs ADD?
COPYis a straightforward command for copying files and directories.ADDprovides additional functionality like automatic extraction of compressed files and support for URLs. However, it adds some complexity and may have unexpected behavior in certain scenarios.It's generally recommended to use
COPYunless you specifically need the features provided byADD.What is the Difference between the Docker command CMD vs RUN?
CMDsets the default command and arguments to be executed when running a container, whereasRUNis used to execute commands during the image build process.CMDis effective during container runtime, whileRUNis executed during the image build process.CMDis typically used to specify the main command for the container, whileRUNis used for actions like installing dependencies, configuring the environment, or executing other build-time tasks
How Will you reduce the size of the Docker image?
• Use a minimal base image
• Minimize installed dependencies
• Optimize resource usage.
Why and when to use Docker?
Reasons to use Docker
• Simplified Environment Setup
• Portability
• Scalability and Flexibility
• Rapid Deployment and Continuous Integration/Continuous Deployment (CI/CD)
• Version Control and Collaboration
Explain the Docker components and how they interact with each other.
Docker Engine: Docker Engine is the core component of Docker. It is responsible for building and running containers. It includes three main parts:
Docker daemon: The Docker daemon (docked) runs on the host system and manages Docker objects such as images, containers, networks, and volumes. It handles requests from the Docker client and communicates with the container runtime.
REST API: Docker Engine exposes a RESTful API that allows communication with the Docker daemon. The API provides various endpoints to interact with Docker resources programmatically.
Docker CLI: The Docker Command-Line Interface (CLI) is a command-line tool that allows users to interact with Docker Engine. It provides a set of commands for managing images, containers, networks, and other Docker objects.
Docker Images: Docker images are the building blocks of containers
Docker Containers: Containers are running instances of Docker images. Each container is isolated from other containers and the underlying system, ensuring that the software runs consistently regardless of the environment. Containers are lightweight and portable, and provide an isolated runtime environment for applications.
Docker Registry: Docker Registry is a centralized repository for Docker images. It stores and distributes Docker images across different environments. The default public Docker Registry is Docker Hub, where you can find a vast collection of pre-built images.
The interaction between these components is as follows:
The Docker CLI communicates with the Docker daemon (dockerd) through the Docker REST API. It sends commands to the daemon for actions like building images, creating containers, starting/stopping containers, and managing other Docker objects.
Docker images are built using the Docker Engine, which reads the instructions from a Dockerfile and creates a layered image based on those instructions. The resulting image is stored in a local or remote Docker registry.
Docker containers are created from Docker images using the Docker Engine. The Docker daemon manages the lifecycle of containers, ensuring their proper execution, resource allocation, and isolation.
Docker Compose leverages the Docker Engine to create and manage multi-container applications based on the specifications defined in a Compose file. It simplifies the orchestration and deployment of complex application stacks.
Container orchestration tools like Kubernetes or Docker Swarm interact with the Docker Engine to manage the deployment, scaling, and monitoring of containers across multiple hosts or clusters.
Explain the terminology: Docker Compose, Docker File, Docker Image, Docker Container?
Docker Compose is a tool that simplifies the management of multi-container applications. It allows you to define and run multiple Docker containers as a single application using a simple YAML configuration file.
Docker File is a text file that contains a set of instructions to build a docker image.
Docker Image is a lightweight, standalone, and executable package that contains
everything needs to run the software.
Docker container is a lightweight and portable runtime environment that runs on top of a host machine's operating system. It is an instance of a Docker image and contains all the necessary application code, libraries, and dependencies required to run an application.
Docker vs Hypervisor?
Docker utilizes containerization, while hypervisors use full virtualization.
Architecture
Docker: Docker uses containerization, which is a lightweight form of virtualization. It runs applications in isolated containers that share the host system's operating system kernel.
Hypervisor: Hypervisors, also known as virtual machine monitors (VMMs), create virtual machines (VMs) that run guest operating systems on top of a host operating system.
Resource Efficiency
Docker: Containers are lightweight and share the host system's resources, such as the OS kernel, libraries, and system binaries.
Hypervisor: VMs created by hypervisors emulate complete hardware, including the OS kernel, resulting in higher resource consumption and slower startup times compared to Docker containers.
What are the advantages and disadvantages of using docker?
Advantages of Docker
• Portability
• Isolation
• Resource Efficiency
• Scalability
Disadvantages of Docker
• Security Concerns
• Limited Windows Support
What is a Docker namespace?
In Docker, a namespace is a feature of the Linux kernel that provides process isolation and resource separation. Docker utilizes namespaces to create an isolated environment for each container, ensuring that processes running inside a container cannot see or interfere with processes outside of it.
What is a Docker registry?
Docker registry is a centralized repository that stores Docker images.
What is an entry point?
The entry point defines the default behavior of the container and the command that will be executed when the container is launched.
Will data on the container be lost when the docker container exits
When a Docker container exits, any data or changes made within the container are typically lost unless you take specific steps to preserve them. Docker containers are designed to be lightweight and disposable, so they don't retain data by default
What are the docker commands for the following?
To view the list of containers in Docker,
docker ps
To view all containers, including the ones that have exited or are stopped
docker ps -a
Command to run the container under a specific name
docker run --name <container_name> <image_name>
Command to export a docker
docker export <container_id> > <output_file.tar>
Command to import an already existing docker image
docker import <input_file.tar> repository:tag
Commands to delete a container
docker rm <container_id>
Command to remove all stopped containers, unused networks, build caches, and dangling images?
docker system prune -f

I appreciate you taking the time to read my blog, and I hope you found it informative. If you found the content useful, please consider giving it a like, sharing it with others, and following me for more similar posts in the future. Thank you for your support!
Linkedin Profile-https://www.linkedin.com/in/shreyakhangan/
Comments
Join the discussionNo comments yet. Be the first to comment.



