Debug School


Posted on


  1. What is Docker and why is it used?

Docker is an open-source platform that allows developers to automate the deployment and management of applications
within containers. Containers provide a lightweight and isolated environment to run applications and their dependencies consistently across different environments. It's used for having the Portability, Efficiency & less Cost.

  1. What is a Docker image and how is it different from a Docker container?
    Docker image is a read-only template or snapshot that contains the instructions for creating a Docker container. Its packaged and self-contained unit that includes everything needed to run an application.
    Docker container is a running instance of a Docker image. It can be thought of as a lightweight, isolated, and executable environment

  2. How do you create a Docker image and run a Docker container?
    docker run -d --name container_name image_name

  3. What is a Dockerfile and how do you use it to create a Docker image?
    Dockerfile is a text file that contains a set of instructions used to build a Docker image.
    docker build -t image_name

  4. How can you inspect the contents of a Docker container and the changes made to a container while it was running?
    docker exec -it container_name /bin/bash
    docker inspect container_name

  5. How can you share a Docker image with others and pull an image from a Docker registry?
    To share the docker image, we need to push the image to a Docker registry. A Docker registry is a centralized repository where Docker images are stored and can be accessed by others. The most common Docker registry is Docker Hub.
    docker push username/repository
    docker pull username/repository

  6. What are the different network modes available in Docker and how do you choose the right network mode for your application?
    Docker provides different network modes to facilitate communication between containers and the host system or other containers. The available network modes are Bridge, Host, None,Overlay & Macvlan network modes.
    Default bridge network mode for most applications that require container-to-container communication within a single host.
    Host network mode when you need maximum network performance and don't require network isolation.
    Overlay network mode for multi-host deployments or container orchestration using Docker Swarm.
    None network mode when you want to run a container without network access or configure networking explicitly inside the container.
    Macvlan network mode when containers need direct connectivity to the physical network, resembling separate physical devices.

  7. How can you mount a volume in a Docker container and share data between the host and container?
    Create volume using - docker volume create myvolume
    Mount volume - docker run -v volume_name_or_path:container_path
    Access volume - docker volume inspect myvolume

  8. What is the difference between a Docker Compose file and a Dockerfile, and how are they used in deploying multi-container applications?
    Docker Compose file and a Dockerfile serve different purposes in the deployment of multi-container applications.
    A Dockerfile is a text file that contains instructions to build a Docker image. It provides a recipe for creating an image by specifying the base image, adding dependencies, copying files, setting environment variables, and defining commands to run. The Dockerfile defines the configuration and contents of a single container image.
    Docker Compose file is a YAML file that defines and manages multiple containers as a single application. It allows you to describe the services, their relationships, networking, volumes, environment variables, and other configurations required for your multi-container application. Docker Compose simplifies the management of multiple containers, allowing you to start, stop, scale, and link them together.

  9. How can you monitor the performance of a Docker container and diagnose issues with it?
    Command used to monitor the peformance.

  10. docker stats container_name displays real-time statistics about CPU usage, memory consumption, network I/O, and disk I/O for a specific container.

  11. docker logs container_name command to view the logs of a specific container

  12. APM Tools

  13. Components of Docker and its Brief Summary
    Docker is composed of several key components that work together to enable containerization and container management.
    Docker Engine is the core runtime environment for containers.
    Docker images are read-only templates or snapshots that contain the necessary files, dependencies, and configurations to run an application.
    Docker containers are runnable instances of Docker images. Containers encapsulate an application and its dependencies, providing an isolated and consistent runtime environment.
    Docker Registries are repositories that store and distribute Docker images. Docker Hub is the default public registry.

  14. What is the differenet between docker pause and unpause?
    These are used to temporarily pause and resume the execution of a running container, respectively.
    Docker pause command is used to freeze the execution of a running container. When you pause a container, its processes are halted, and it enters a suspended state. The container's file system and memory state remain intact, but its CPU and system resources are no longer utilized.
    docker pause container_name

Docker unpause command is used to resume the execution of a paused container. It reverses the effects of the docker pause command, allowing the container's processes to continue running. When you unpause a container, it returns to its normal operating state, and CPU and system resources are once again allocated to it
docker unpause container_name

  1. What is the differenet between docker stop and kill? Docker stop command is used to gracefully stop a running container by sending a termination signal (SIGTERM) to the container's main process. docker stop container_name

Docker kill command is used to forcefully terminate a running container by sending a termination signal (SIGKILL) to the container's main process. When a container receives the SIGKILL signal, it is immediately terminated without any opportunity for cleanup or graceful shutdown

Docker stop provides a graceful way to stop a container, allowing it to clean up resources and shut down properly. It provides a chance for running processes to perform any necessary cleanup actions. On the other hand, docker kill forcefully terminates a container without giving it an opportunity to clean up. It is useful when immediate termination is required or when a container is unresponsive.

  1. What is the differenet between docker exec and attach? Docker exec command is used to execute a command inside a running container. It allows you to run commands or scripts in an existing container, interacting with its environment and processes. When you use docker exec, a new process is started within the container, and you can specify the command to run as an argument. docker exec container_name command

Docker attach command is used to attach the host's standard input, output, and error streams to a running container. It connects the terminal or shell session to the container's main process, allowing you to see its output and interact with it directly. When you use docker attach, you connect to the main process of the container that was started when the container was launched
docker attach container_name

  1. List of dockerfile instructions and its Brief Summary? Commonly used dockerfile instructions. FROM: Specifies the base image for your Docker image. It defines the starting point for building your image and can be an official image from Docker Hub or a custom image you've created.

MAINTAINER (deprecated): Specifies the name and email address of the image maintainer. This instruction is deprecated, and it's recommended to use the LABEL instruction instead to provide metadata about the image.

LABEL: Adds metadata to the Docker image. You can include information such as version, author, description, or any custom labels that are useful for identification and organization.

RUN: Executes a command during the build process. It allows you to run commands within the image, such as installing dependencies, configuring the environment, or running build scripts.

CMD: Specifies the default command to be executed when a container is started from the image. CMD can be overridden at runtime if a command is passed as an argument when starting the container.

ENTRYPOINT: Sets the primary command for the container. Unlike CMD, ENTRYPOINT doesn't allow overriding the command with arguments. It's often used to define the main executable for the containerized application.

USER: Sets the user or UID (user identifier) for subsequent instructions. It allows you to switch from the default root user to a non-root user within the image for improved security and best practices.

RUN (multi-line form): Executes multiple commands as a single instruction. It allows you to combine multiple commands into a single layer in the image, reducing the number of intermediate layers and optimizing the image size.

  1. What is the differenet between CMD vs Entry CMD instruction sets the default command and parameters for the container. It specifies the command that should be executed when a container is run from the image. It allows you to define the main behavior of the container, such as the primary process that runs inside the container. The CMD instruction is typically used to provide default command-line arguments or parameters to the container's main process. It can be overridden by passing a command as an argument when running the container.

The ENTRYPOINT instruction sets the primary command for the container. It specifies the executable or script that should be executed when a container is run from the image. The ENTRYPOINT instruction is similar to CMD, but it does not allow the command to be overridden with additional arguments at runtime.

CMD specifies the default command and/or parameters for a container and can be overridden at runtime.
ENTRYPOINT sets the primary command for a container and does not allow the command to be overridden.

Top comments (0)