50 Docker Questions- Must to know

Here are 50 Docker questions ranging from basic to advanced, along with their answers:

IN TODAY'S EDIT

Use Case

Docker Questions- Must to know

🚀 Top News

Siri's Silent Listen: Apple's $95 million privacy settlement and what it means for you

📚️ Resources :

Learn New Thing: Tutorial for Selenium automation testing tool lovers.

Want to prepare for Interviews & Certifications

Before we begin... a big thank you to Friend Support.

Inviul

Inviul is the multi niche learning platform. It covers various topics like Selenium, Appium,Cucumber, Java and many more.

USE CASE

Docker Questions- Must to know

Basic Docker Questions:

  1. What is Docker?
    Docker is an open-source platform that automates the deployment, scaling, and management of applications using containerization.

  2. What is a Docker container?
    A Docker container is a lightweight, standalone, and executable package that includes everything needed to run an application, such as code, runtime, system tools, libraries, and settings.

  3. How is a Docker container different from a virtual machine?
    Containers share the host OS kernel, while VMs include a full OS instance. Containers are lightweight and faster compared to VMs.

  4. What is a Docker image?
    A Docker image is a lightweight, stand-alone, and executable software package that contains everything needed to run a piece of software.

  5. What is the difference between Docker image and container?
    A Docker image is a blueprint or template for containers, whereas a container is a running instance of an image.

  6. What is Dockerfile?
    A Dockerfile is a script containing a series of instructions on how to build a Docker image.

  7. What is the purpose of the docker run command?
    The docker run command is used to create and start a container from a specified image.

  8. What is the syntax to build an image from a Dockerfile?
    docker build -t <image_name> .

  9. What command is used to list running containers?
    docker ps

  10. How to stop a running container?
    docker stop <container_id>

  11. What is the command to remove a Docker container?
    docker rm <container_id>

  12. How do you remove an image in Docker?
    docker rmi <image_id>

  13. How can you check Docker logs of a container?
    docker logs <container_id>

  14. What is a Docker volume?
    A Docker volume is a mechanism for persisting data generated and used by Docker containers.

  15. How do you create a volume in Docker?
    docker volume create <volume_name>

  16. What command is used to enter an interactive shell inside a running container?
    docker exec -it <container_id> bash

  17. How do you list all Docker networks?
    docker network ls

  18. What is the default network mode in Docker?
    The default network mode is bridge.

  19. How do you check Docker version installed on your system?
    docker --version

  20. How do you run a container in detached mode?
    docker run -d <image_name>

Intermediate Docker Questions:

  1. How do you restart a Docker container?
    docker restart <container_id>

  2. What is the difference between CMD and ENTRYPOINT in Dockerfile?
    CMD provides default arguments for an executable, while ENTRYPOINT defines the actual executable to be run.

  3. How do you inspect details of a container?
    docker inspect <container_id>

  4. What is the use of the .dockerignore file?
    The .dockerignore file excludes specified files and directories from the Docker build context.

  5. What is the purpose of the docker-compose tool?
    Docker Compose is used to define and run multi-container Docker applications using a YAML configuration file.

  6. How do you scale containers using Docker Compose?
    docker-compose up --scale <service_name>=3

  7. What is the difference between a bind mount and a volume?
    A volume is managed by Docker, whereas a bind mount links a host directory to a container.

  8. How do you pass environment variables to a Docker container?
    Using the -e flag: docker run -e VAR_NAME=value <image_name>

  9. What is a multi-stage build in Docker?
    Multi-stage builds allow using multiple FROM instructions to optimize the final image size by discarding unnecessary build artifacts.

  10. How do you copy files from a running Docker container to the host?
    docker cp <container_id>:/path/to/file /host/path

  11. How do you set resource limits for a container?
    Using flags such as --memory and --cpu in the docker run command.

  12. What are Docker namespaces?
    Docker namespaces provide isolation of resources such as PID, network, and file systems between containers.

  13. What is Docker Swarm?
    Docker Swarm is a native clustering and orchestration tool for managing Docker containers across multiple nodes.

  14. What is a Docker Registry?
    A Docker registry is a storage and distribution system for Docker images, such as Docker Hub or private registries.

  15. How do you push an image to Docker Hub?
    docker push <username>/<image_name>:<tag>

  16. What is the difference between docker stop and docker kill?
    docker stop gracefully shuts down a container, whereas docker kill forcefully terminates it.

  17. How do you expose a port while running a container?
    docker run -p 8080:80 <image_name>

  18. How can you configure a container to restart automatically?
    Using --restart flag with options like always, on-failure, etc.

  19. What is the purpose of the docker prune command?
    It removes unused containers, networks, and images to free up disk space.

  20. What is an overlay network in Docker?
    An overlay network allows containers running on different Docker hosts to communicate.

Advanced Docker Questions:

  1. How do you secure Docker containers?
    By using practices such as image scanning, limiting privileges, enabling seccomp profiles, and using network segmentation.

  2. What is the difference between Docker and Kubernetes?
    Docker is a containerization platform, whereas Kubernetes is an orchestration system to manage containerized applications.

  3. How can you debug a failed Docker build?
    By using the --progress=plain flag and analyzing each build step.

  4. What are Docker storage drivers?
    Storage drivers manage how Docker writes and reads images and containers, such as overlay2, aufs, etc.

  5. What is the significance of the HEALTHCHECK instruction in Dockerfile?
    It provides a way to monitor the health of a running container.

  6. How do you deploy a containerized application in production?
    Using orchestration tools like Kubernetes, Docker Swarm, or ECS.

  7. What are Docker secrets, and how do they work?
    Docker secrets securely store and manage sensitive data, such as passwords and API keys, in Docker Swarm mode.

  8. What is BuildKit in Docker?
    BuildKit is an advanced build backend that improves performance and caching in Docker builds.

  9. How does Docker ensure isolation between containers?
    Through technologies such as cgroups, namespaces, and kernel features.

  10. What are the best practices for writing a Dockerfile?

  • Use minimal base images

  • Leverage caching effectively

  • Avoid unnecessary layers

  • Use multi-stage builds

  • Keep the image size small

Reply

or to participate.