Docker Interview Questions
What is the difference between an Image and a Container?
Images | Container |
It is a blueprint of the Container | It is an instance of the Image. |
Images are created only once. | Containers are created any number of times using an image. |
Sharing of Docker Images is possible. | Sharing of containers is not possible directly. |
It has multiple read-only layers. | It has a single writable layer. |
These image templates can exist in isolation. | These containers cannot exist without images. |
What is the Difference between the Docker command COPY vs ADD?
COPY | ADD |
COPY is a docker file command that copies files from a local source location to a destination in the Docker container | ADD command is used to copy files/directories into a Docker image. |
The source is always local | It can also copy files from a URL. |
What is the Difference between the Docker command CMD vs RUN?
CMD | RUN |
CMD s the command the container executes by default when you launch the built image. | RUN is an image build step, the state of the container after a RUN command will be committed to the container image |
A Dockerfile will only use the final CMD defined | A Dockerfile can have many RUN steps that layer on top of one another to build the image. |
If docker file runs with an argument the CMD command gets ignored | RUN commands are never ignored |
Q: How Will you reduce the size of the Docker image?
If we take a container image of a typical application, it contains a base image, Dependencies/Files/Configs, and cruft (unwanted software).So its important to ensure that the docker image is not getting bloated after application builds
Using distroless/minimal base images
Multistage builds
Minimizing the number of layers
Understanding caching
Using Dockerignore
Keeping application data elsewhere
Q: Explain the Docker components and how they interact with each other.
https://hashnode.com/edit/clh1s5jwi00010amm9aztcwoz
Q: Explain the terminology: Docker Compose, Docker File, Docker Image, Docker Container, Docker registry?https://hashnode.com/edit/clh1s5jwi00010amm9aztcwoz
Q: Docker vs Hypervisor?
| Virtual Machines (VMs) | |
Boot-Time | Boots in a few seconds. | It takes a few minutes for VMs to boot. |
Runs on | Dockers make use of the execution engine. | VMs make use of the hypervisor. |
Memory Efficiency | No space is needed to virtualize, hence less memory. | Requires entire OS to be loaded before starting the surface, so less efficient. |
Isolation | Prone to adversities as no provisions for isolation systems. | Interference possibility is minimum because of the efficient isolation mechanism. |
Deployment | Deploying is easy as only a single image, containerized can be used across all platforms. | Deployment is comparatively lengthy as separate instances are responsible for execution. |
Usage | Docker has a complex usage mechanism consisting of both third-party and docker-managed tools. | Tools are easy to use and simpler to work with |
Q: 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. Each aspect of a container runs in a separate namespace and its access is limited to that namespace.
Q: What is an ENTRYPOINT?
An ENTRYPOINT
allows you to configure a container that will run as an executable.You can override the ENTRYPOINT
instruction using the docker run --entrypoint
flag.Only the last ENTRYPOINT
instruction in the Dockerfile
will have an effect.
Q: Will data on the container be lost when the docker container exits?
Not at all! Any data your application writes to disk gets preserved in its container until you explicitly delete it. The file system for the container persists even after the container halts.
Q: What is a Docker swarm?
A docker swarm is a container Orchestration tool. It helps in Deployment and maintenance of multiple containers for an application.It mainly consist of mainly manager nodes and worker nodes.
Q: What are the docker commands for the following:
view running containers :
docker ps
* command to run the container under a specific name:
docker container run –-name
* command to export a docker container:
docker export [OPTIONS] CONTAINER
* command to import an already existing docker image:
docker import
* commands to delete a container :
docker rm <container id/name>
* command to remove all stopped containers, unused networks, build caches, and dangling images:
docker system prune
Hope you find it useful!!!