Day 21 Task: Docker Important interview Questions.

Docker Interview

Docker is a good topic to ask in DevOps Engineer Interviews, mostly for freshers. One must surely try these questions in order to be better in Docker

Questions

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

The key difference between a Docker image vs a container is that a Docker image is a template that defines how a container will be realized. A Docker container is a runtime instance of a Docker image. Docker Engine is an open source containerization technology for building and containerizing your applications. 

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

COPY and ADD are both Dockerfile instructions that serve a similar purpose. They let you copy files from a specific location into a Docker image.

COPY takes in a source and destination. It only lets you copy in a local or directory from your host (the machine-building the Docker image) into the Docker image itself.

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

RUN is an image build step, the state of the container after a RUN command will be committed to the container image. A Dockerfile can have many RUN steps that layer on top of one another to build the image.

CMD is the command the container executes by default when you launch the built image. A Dockerfile will only use the final CMD defined. The CMD can be overridden when starting a container with docker run $image $other_command.

How Will you reduce the size of the Docker image?

Increase docker storage size

  1. Stop the kubelet service: systemctl stop kubelet. service.
  2. Inside the node, run systemctl stop docker. service to stop docker service.
  3. Change the docker base size to 110G in the config files. ...
  4. Restart the docker service: systemctl start docker.

Why and when to use Docker?

The value of Docker for DevOps continues as it enables an entirely isolated application to be deployed to multiple servers. As it spreads to the servers, no other applications can access it. The only exposure of the container is to the internet and the Docker client.

We can use Docker to wrap up an application in such a way that its deployment and runtime issues—how to expose it on a network, how to manage its use of storage and memory and I/O, how to control access permissions—are handled outside of the application itself, and in a way that is consistent across all “containerized 

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

Docker works via a Docker engine that is composed of two key elements: a server and a client; and the communication between the two is via REST API. The server communicates the instructions to the client.

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

Docker Compose: A command-line tool and YAML file format with metadata for defining and running multi-container applications. You define a single application based on multiple images with one or more .yaml files that can override values depending on the environment. After you've created the definitions, you can deploy the whole multi-container application with a single command (docker-compose up) that creates a container per image on the Docker host.

Dockerfile: A text file that contains instructions for building a Docker image. It's like a batch script, the first line states the base image to begin with and then follow the instructions to install required programs, copy files, and so on, until you get the working environment you need.

Docker image:  A package with all the dependencies and information needed to create a container. An image includes all the dependencies (such as frameworks) plus deployment and execution configuration to be used by a container runtime. Usually, an image derives from multiple base images that are layers stacked on top of each other to form the container's filesystem. An image is immutable once it has been created.

Docker Container: An instance of a Docker image. A container represents the execution of a single application, process, or service. It consists of the contents of a Docker image, an execution environment, and a standard set of instructions. When scaling a service, you create multiple instances of a container from the same image. Or a batch job can create multiple containers from the same image, passing different parameters to each instance.

In what real scenarios have you used Docker?

Docker is one of the recent most successful open source project which provides packaging, shipping, and running any application as light weight containers. We can actually compare Docker containers as shipping containers that provides standard consistent way of shipping any application.

Docker vs Hypervisor?

Hypervisors are of two types – the bare metal works directly on the hardware while type two hypervisor works on top of the operating system.

Docker, on the other hand, works on the host kernel itself. Hence, it does not allow the user to create multiple instances of operating systems.

What are the advantages and disadvantages of using docker?

Advantages of Docker

  • Docker produces an API for container management – Docker produces an API for container management in an image format and a chance to use a remote registry for sharing containers. This scheme serves both developers and system administrators with advantages for instance.
  • Fast application deployment – containers carry the minimal runtime requirements of the application, decreasing their size and enabling them to be deployed instantly.
  • Transferable across machines – an application and all its dependencies can be grouped into a separate container that is autonomous from the host version of Linux kernel, platform configuration, or deployment type. This container can be assigned to another machine that runs Docker and performed there without adaptability issues.
  • Version control and component retain – you can pursue succeeding versions of a container, inspect irregularities or go back to previous versions. Containers reuse segments from the preceding layers, which makes them remarkably light.
  • Sharing – you can use a distant repository to share your container with others. Red Hat provides a registry for this purpose, and it is also desirable to configure your own individual repository.
  • Light and minimal overhead – Docker images are typically very small, which promotes rapid delivery and reduces the time to deploy new application containers.

Disadvantages of Docker

  • Containers don’t work at bare-metal rates – Containers utilise resources more efficiently than virtual machines. But containers are however directed to performance overhead due to overlay networking, interfacing within containers and the host system and so on. If you want 100% bare-metal performance, you want to apply bare metal, not containers.
  • The container ecosystem is split – But the core Docker platform is open source, some container products don’t work with other ones.
  • Data storage is intricate – By design, all of the data inside a container leaves forever when it closes down except you save it somewhere else first. There are ways to store data tenaciously in Docker, such as Docker Data Capacities, but this is arguably a test that still has yet to be approached in a seamless manner.
  • Graphical applications do not operate well – Docker was created as a solution for deploying server applications that don’t need a graphical interface. While there are some creative approaches that one can practice to run a GUI app inside a container, these solutions are solid at best.
  • Few applications do not benefit from Docker Containers – In common, the applications that are intended to work as a collection of thoughtful microservices attain to get the most from containers. Contrarily, Docker’s one real benefit is that it can interpret application delivery by giving an easy packaging mechanism.

What is a Docker namespace?

Docker uses a technology called namespaces to provide the isolated workspace called the container. When you run a container, Docker creates a set of namespaces for that container. These namespaces provide a layer of isolation.

What is a Docker registry?

A Docker registry is a storage and distribution system for named Docker images. The same image might have multiple different versions, identified by their tags. A Docker registry is organized into Docker repositories , where a repository holds all the versions of a specific image.

What is an entry point?

A particular place where a person or thing can enter something or somewhere. The site has several entry points. entry point to something The emergency services closed all entry points to the square.

How to implement CI/CD in Docker?

  1. Create a new GitHub repository using this template repository. ...

2. Open the repository Settings, and go to Secrets > Actions.

3. Create a new secret named DOCKERHUB_USERNAME and your Docker ID as value.

4. Create a new Personal Access Token (PAT) for Docker Hub.

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

After a container finishes executing its default command, it will stop. When you run a container image you've pulled from a registry like Docker Hub, you're launching a process. This process will, eventually, complete.

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:

  • view running containers - "docker ps” or “docker container ls"
  • command to run the container under a specific name - docker exec -it <container name> <command>
  • command to export a docker - docker export [OPTIONS] CONTAINER
  • command to import an already existing docker image - docker images
  • commands to delete a container - docker rm -f < Container_ID>
  • command to remove all stopped containers, unused networks, build caches, and dangling images? - To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command: docker system prune -a.

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

  • Method 1: Use Minimal Base Images. ...
  • Method 2: Use Docker Multistage Builds. ...
  • Method 3: Minimize the Number of Layers. ...
  • Method 4: Understanding Caching. ...
  • Method 5: Use Dockerignore. ...
  • Method 6: Keep Application Data Elsewhere.

These questions will help you in your next DevOps Interview. 

Happy Learning :)

To view or add a comment, sign in

More articles by Deepika D

  • Day 28 Task: Jenkins Agents

    Jenkins Master (Server) Jenkins’s server or master node holds all key configurations. Jenkins master server is like a…

    4 Comments
  • Day 27 Task: Jenkins Declarative Pipeline with Docker

    Use your Docker Build and Run Knowledge docker build - you can use sh 'docker build . -t <tag>' in your pipeline stage…

    1 Comment
  • Day 26 Task: Jenkins Declarative Pipeline

    One of the most important parts of your DevOps and CICD journey is a Declarative Pipeline Syntax of Jenkins Some terms…

  • Day 24 Task: Complete Jenkins CI/CD Project

    Let's make a beautiful CI/CD Pipeline for your Node JS Application Task-01 Fork this repository: Create a connection to…

  • Day 23 Task: Jenkins Freestyle Project for DevOps Engineers.

    What is CI/CD? CI or Continuous Integration is the practice of automating the integration of code changes from multiple…

  • Day-22 : Getting Started with Jenkins

    1. What is Jenkins? Jenkins is an open source continuous integration-continuous delivery and deployment (CI/CD)…

  • Day 20 Task : Docker commands Cheat-Sheet

    Docker commands: # docker build: Builds an image from a Dockerfile. docker build [OPTIONS] PATH | URL | docker build…

  • Day 19 Task: Docker for DevOps Engineers

    Docker-Volume Docker allows you to create something called volumes. Volumes are like separate storage areas that can be…

    3 Comments
  • Day 18 Task: Docker for DevOps Engineers

    Docker Compose Docker Compose is a tool that was developed to help define and share multi-container applications. With…

  • Day 17 Task: Docker Project for DevOps Engineers.

    Dockerfile Docker is a tool that makes it easy to run applications in containers. Containers are like small packages…

Others also viewed

Explore content categories