#90DAYSOFDEVOPSCHALLENGE

Day 21 Task: Docker Important interview Questions.

Abhay Vishwakarma
7 min readFeb 7, 2023

What is the Difference between an Image, Container and Engine..?

  • Image : Docker Image is an executable package of software that includes everything needed to run an application. This image informs how a container should instantiate, determining which software components will run and how.
  • Container : Docker container is a virtual environment that bundles application code with all the dependencies required to run the application. The application runs quickly and reliably from one computing environment to another.
  • Engine : Docker Engine is an open source containerization technology for building and containerizing your applications. Docker Engine acts as a client-server application.

What is the Difference between the Docker command COPY vs ADD..?

The COPY command is used to copy files from the host system to the container, while the ADD command can do the same but also supports file compression and URL sources.

What is the Difference between the Docker command CMD vs RUN..?

The CMD command is used to specify the default command that should be executed when a container is started from an image. This command can be overridden when starting a container, which means that it does not have to be executed every time a container is started.

The RUN command, on the other hand, is used to execute a command during the image building process. It will run command(s) in a new layer on top of the current image and commit the results. The command(s) in a RUN instruction will always be executed when the image is being built.

How Will you reduce the size of the Docker image..?

To reduce the size of a Docker image, you can use multi-stage builds, remove unnecessary files and dependencies, and use smaller base images.

  • Multi-stage builds : Use multiple Dockerfiles in a multi-stage build process to only include the final required artifacts in the final image, discarding intermediate build artifacts and unused files.
  • Use smaller base images : Select base images with the smallest possible size, for example, using Alpine Linux instead of full-featured distributions like Ubuntu.

Why and when to use Docker..?

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications.

Explain the Docker components and how they interact with each other..?

- Docker has several components, including the Docker daemon, which manages the creation and management of containers, the Docker client, which communicates with the daemon to issue commands, and the Docker registry, which stores and distributes images.

  • Docker Daemon : The Docker Daemon is the core component of Docker, responsible for building, running, and managing containers. It communicates with other components through the Docker API.
  • Docker CLI : The Docker CLI is a command-line interface for interacting with the Docker Daemon. Users can use the CLI to build, run, and manage containers.

Explain the terminology: Docker Compose, Docker File, Docker Image, Docker Container..?

  • Docker File: A Docker File is a script that contains instructions for building a Docker Image. It specifies the base image, files to be copied, and commands to run when building the image.
  • Docker compose : It is a tool for defining and running complex applications with Docker. With Compose, you define a multi-container application in a single file, then spin your application up in a single command which does everything that needs to be done to get it running.
  • Docker image : A Docker Image is a snapshot of a file system that contains all the files and dependencies needed to run an application. It is created from a Docker File and can be used to create new containers.
  • Docker Container : A container is a runtime instance of a docker image A Docker container consists of A Docker image An execution environment A standard set of instructions.

In what real scenarios have you used Docker..?

I have used Docker in a variety of scenarios including development, CI/CD, microservices architecture, testing and staging, production, virtualization of legacy app, big data and data science environment. It allows for consistency and reproducibility in builds, easy scaling and management of applications, and efficient use of system resources.

Docker vs Hypervisor..?

  • Docker : Docker is designed for application virtualization, where each application runs in its own container. Containers share the host operating system, making them lightweight and efficient. Docker is ideal for microservices and cloud-based deployments.
  • Hypervisor : A hypervisor is a layer of software that allows multiple virtual machines to run on a single physical machine. Each virtual machine runs its own operating system and has its own resources, making it ideal for server virtualization and multi-tenant environments.

What are the advantages and disadvantages of using docker..?

  • Advantages of using Docker:

1. Portability: Docker containers can run on any system that supports the Docker engine, making it easy to move applications between environments.

2. Isolation: Docker containers provide a level of isolation between applications, which can help prevent conflicts between dependencies and reduce the risk of security vulnerabilities.

3. Resource efficiency: Docker containers are lightweight and consume fewer resources than virtual machines, which can help reduce costs and improve performance.

4. Scalability: Docker makes it easy to scale applications by adding or removing containers as needed.

5. Automation: Docker allows you to automate the process of building, testing, and deploying applications, which can help to improve the efficiency of the software development life cycle.

6. Microservices: Docker helps in implementing a microservices architecture, allowing you to break down a monolithic application into smaller, loosely-coupled services.

  • Disadvantages of using Docker:

1. Complexity: Setting up and managing a Docker environment can be complex, especially for large, complex applications.

2. Security: Docker containers share the host’s kernel, which can make it easier for attackers to compromise the host and gain access to the containers.

3. Volume management: Docker does not provide built-in volume management, which can make it difficult to manage data volumes across containers.

4. Limited Windows support: Windows support for Docker is not as robust as Linux support, which can make it more difficult to run Windows-based applications in a container.

5. Networking: Docker networking can be complex and may require additional configuration to work properly.

What is a Docker namespace..?

A Docker namespace is a virtualized environment for certain system resources, such as network interfaces, that is used to isolate containers from one another.

What is a Docker registry..?

A Docker registry is a service that stores and distributes Docker images, and it allows users to upload, download, and manage their own images. It can be either public or private, and it can support different authentication and authorization mechanisms to control access to the images.

What is an entry point..?

An entry point is a command that is run when a container is started from an image.

How to implement CI/CD in Docker..?

CI/CD (Continuous Integration/Continuous Deployment) in Docker can be implemented by following these steps:

1. Build: Use a continuous integration tool, such as Jenkins, Travis CI or CircleCI, to automatically build a Docker image from the source code whenever there are changes to the codebase. This can be done by using a Dockerfile to define the image and using the CI tool to run the docker build command.

2. Test: Run automated tests on the built image to ensure that the application is functioning correctly. This can be done by starting a container from the image and running the tests inside the container.

3. Push: Push the built image to a Docker registry, such as Docker Hub, so that it can be easily accessed by the deployment environment.

4. Deploy: Use a continuous deployment tool, such as Kubernetes or Docker Swarm, to deploy the image to the production environment. This can be done by pulling the image from the registry and starting a container from it.

5. Monitor: Monitor the deployed containers to ensure that they are running correctly and that there are no issues with the application. This can be done by using tools such as Prometheus or Elasticsearch, Logstash and Kibana.

Will data on the container be lost when the docker container exits..?

Data stored on a container will be lost when the container is removed, unless steps are taken to preserve it. By default, when a container is removed, all data stored in the container’s file system is also removed.

What is a Docker swarm..?

A Docker Swarm is a group of either physical or virtual machines that are running the Docker application and that have been configured to join together in a cluster.

The activities of the cluster are controlled by a swarm manager, and machines that have joined the cluster are referred to as nodes.

What are the docker commands for the following :

  • To view running containers :
docker ps
  • To run the container under a specific name :
docker run --name <name> <image>
  • Export a docker container :
docker export <container> > <filename>
  • To import an already existing docker image :
docker import <filename> <repository:tag>
  • To delete a container :
docker rm <container>
  • Command to remove all stopped containers, unused networks, build caches, and dangling images :
docker system prune

What are the common docker practices to reduce the size of Docker Images..?

Here Common practices to reduce the size of Docker images include: using multi-stage builds, removing unnecessary files and dependencies, using smaller base images, using a .dockerignore file, squashing multiple layers, using a caching mechanism, version pinning and using image scanning and vulnerability analysis tools. While these practices can help reduce the size of images, it’s important to consider the impact on the functionality of the application.

Thank you for reading this blog. I hope you find this really interesting.

If you like it then press ‘Clap’ button and Follow me on Linkedin & Github platform.

— Abhay Vishwakarma

--

--