📂Day 21 - Docker Important Interview Questions

📂Day 21 - Docker Important Interview Questions

1. Difference between an Image, Container, and Engine:

◼️ Image: It's like a snapshot of all the files and settings needed to run a program.

◼️ Container: A container is like a box that holds everything your program needs to run, including the program itself and any other stuff it needs.

Engine: The engine is like the boss that manages the containers, making sure they start, stop, and run smoothly.

2. Docker command COPY vs ADD:

COPY is like a basic copy-paste command for files. It's simple and good for most file copying needs.

ADD can do more than just copy files. It can also extract compressed files like zip or tar, and copy files from a URL. But it's not always needed for basic file copying.

3. Docker command CMD vs RUN:

CMD is like setting the default program to run when you start your container. It tells Docker what to do when the container starts.

RUN is used to run commands when you're building your Docker image. It's like giving instructions to Docker on how to set up your image before it becomes a running container.

4. Reduce the size of Docker Image:

To keep your Docker image small, use a tiny starting image, combine commands when possible, remove things you don't need, and use multi-stage builds to only keep what's necessary.

5. Why and When to Use Docker:

Docker offers a lightweight, portable, and consistent environment for applications. Its usage streamlines deployment processes, ensuring uniformity across diverse environments.

6. Explaining Docker Components:

◼️ Docker Compose: A tool for defining and running multi-container Docker applications.

◼️ Docker File: A script with build instructions for a Docker image.

◼️ Docker Image: A self-contained package with everything needed to run an application.

◼️ Docker Container: An instantiated and runnable Docker image.

7. Real Scenarios of Using Docker:

Docker is used for breaking down big applications into smaller parts (microservices), making it easier to manage and update them. It's also used in automated pipelines (CI/CD) to test and deploy code faster. Additionally, Docker helps to keep applications and their parts separate and easy to move around (isolation and packaging).

8. Docker vs Hypervisor:

◼️ Docker uses containers that share the host OS, making them lightweight and fast.

◼️ Hypervisors create full virtual machines with their own OS, which can be slower and require more resources.

9. Advantages and Disadvantages of Docker:

◼️ Advantages: Portability, efficiency, rapid deployment, and optimized resource utilization.

◼️ Disadvantages: Security concerns, learning curve, and potential complexity in larger deployments.

10. Docker Namespace:

Linux namespaces are like separate rooms in a house, where each room (namespace) has its own processes. Processes in one room (namespace) can't see or interact with processes in another room, providing isolation and security.

11. Docker Registry:

A repository for Docker images, enabling distribution and sharing. Docker Hub is a popular public registry.

12. Entry Point:

An instruction in a Dockerfile defining the default command to execute when a container starts.

13. Implementing CI/CD in Docker:

CI/CD in Docker involves automating build, test, and deployment processes using tools like Jenkins, GitLab CI, or GitHub Actions.

14. Data Persistence in Docker:

Data on a container is lost by default when it exits. To persist data, use volumes or bind mounts.

15. Docker Swarm:

Docker Swarm is Docker's native clustering and orchestration solution for managing a group of Docker hosts.

16. Common Docker Commands:

◼️ View running containers: docker ps

◼️ Run a container with a specific name: docker run --name container_name

◼️ Export a Docker container: docker export container_id > filename.tar

◼️ Import an existing Docker image: docker import filename.tar

◼️ Delete a container: docker rm container_id

◼️ Remove all stopped containers, unused networks, build caches, and dangling images: docker system prune

17. Practices to Reduce Docker Image Size:

Use a minimal base image.

Consolidate commands in a single layer.

Remove unnecessary dependencies and files.

Leverage multi-stage builds.

Conclusion

These Docker interview questions cover a lot of important topics, giving you a good understanding of Docker. Mastering these concepts will not only help you in interviews but also in real-world projects. Enjoy working with Docker!

😊 Hope you find it helpful !