#90daysofdevops #21

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

  • Difference between Docker Image and Docker Container:

  • "Docker engine" is the part of Docker which creates and runs Docker containers. A Docker container is a live running instance of a Docker image.

    | | Docker Image | Docker Container | | --- | --- | --- | | 1. | It is a blueprint of the Container. | It is an instance of the Image. | | 2. | Image is a logical entity. | Container is a real world entity. | | 3. | Images are created only once. | Containers are created any number of times using an image. | | 4. | Images are immutable. One cannot attach volumes and networks. | Containers change only if the old image is deleted and a new one is used to build the container. One can attach volumes, networks etc. | | 5. | Images do not require computing resources to work. | Containers require computing resources to run as they run with a Docker Virtual Machine. | | 6. | To make a docker image, you have to write script in a Dockerfile. | To make a container from an image, you have to run “docker run <image>” command | | 7. | Docker Images are used to package up applications and pre-configured server environments. | Containers use server information and a file system provided by an image in order to operate. | | 8. | Images can be shared on Docker Hub. | It makes no sense in sharing a running entity, always docker images are shared. | | 9. | There is no such thing as a running state of a Docker Image. | Containers use RAM when created and in running state. | | 10. | An image must not reference to any state to remove the image. | A container must be in a running state to remove it. | | 11. | One cannot connect to the images as these images are like snapshots. | In this, one cannot connect them and execute the commands. | | 12. | Sharing of Docker Images is possible. | Sharing of containers is not possible directly. | | 13. | It has multiple read-only layers. | It has a single writable layer. | | 14. | These image templates can exist in isolation. | These containers cannot exist without images. |

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

  • the ADD directive is more powerful in two ways:

    • It can handle remote URLs(we should use curl or wget to fetch remote files and remove them when no longer needed.)

    • It can auto-extract tar files

      The COPY directive, on the other hand, can only accept local files.

  • 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.

    ENTRYPOINT is also closely related to CMD and can modify the way a CMD is interpreted when a container is started from an image.

  • How Will you reduce the size of the Docker image?

  • Using distroless/minimal base images(Alpine images can be as small as 5.59MB. It’s not just small; it’s very secure as well.)

  • Multistage builds

  • Minimizing the number of layers

  • Understanding caching

  • Using Dockerignore

  • Keeping application data elsewhere

  • Why and when to use Docker?

  • Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications.

  • 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.

  • Traditional vs New Gen

  • Docker Architecture

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

  • Docker Compose is used to run multiple containers as a single service. For example, suppose you had an application which required NGNIX and MySQL, you could create one file which would start both the containers as a service without the need to start each one separately.

  • A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.

  • Docker is used to create, run and deploy applications in containers. A Docker image contains application code, libraries, tools, dependencies and other files needed to make an application run. When a user runs an image, it can become one or many instances of a container.

    Docker images have multiple layers, each one originates from the previous layer but is different from it.

  • A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

  • In what real scenarios have you used Docker?

  • 1) Adoption of DevOps. ...

  • 2) App infrastructure isolation. ...

  • 3) Multi-tenancy support. ...

  • 4) Improvement in software testing. ...

  • 5) Smart Disaster Recovery (DR) ...

  • 6) Continuous rapid deployment. ...

  • 7) Creation of microservices architecture.

  • Docker vs Hypervisor?

  • Hypervisor

    Docker

    Hypervisors can be made to work on software and hardware where it works on the operating system or on the CPU and storage services of the system.

    Dockers work only on the software of the operating system and not on the hardware side. It takes the host kernel and works on the principle of virtualization.

    In a single system, we can use multiple operating systems with the help of Hypervisor. This makes the system to work with multiple users with different methods even for the same program. Hence the same operation is done by different operating systems. 

    Docker does not allow users to create multiple instances of operating systems in the same computer but it makes virtualization by making containers in the same system. Containers help users to work separately on different or the same applications. The same operations are carried out by containers in the system.

    More power and resources are required by the systems using hypervisors as different programs are being run on the same system with different operating systems.

    Resource requirement is low as containers are working on the same operating system and this makes the system share resources within the containers.

    Boot time is high for hypervisors as different operating systems are used. It may take some minutes to start the system and users can resume their work only after booting the machine.

    Boot time is low for dockers as all the containers work on the same machine. User can start the system in seconds and can start working on the same machine.

    We cannot test the same application with different parameters in hypervisor as there is no container method available. This application needs to be developed and tested in the system. If the parameters must be changed, it should be modified in the same operating system itself.

    If the same application needs to be tested in the system with different instances, we can use containers as different parameters can be given to the application in the same container and can be tested at the same time. Dockers support this method of working which is called an agile model.

    Hypervisor works with host OS and guest OS which creates layers that run the hardware. We cannot create different instances for the same application in the system but we can control the hardware and make the system work with both OS.

    Docker does not have an OS for itself and thus it creates instances and parameters by sitting on top of OS. This helps in modifying the instances if needed. It works solely on the host OS and does not control the hardware of the system.

  • What are the advantages and disadvantages of using docker?

  • Advantages:

  • Return on Investment and Cost Savings

  • Rapid Deployment

  • Security

  • Simplicity and Faster Configurations

  • CI Efficiency

  • Continuous Integration

  • Limitations of Docker

  • Missing features

  • Data in the container

  • Run applications as fast as a bare-metal serve

  • Provide cross-platform compatibility

  • Run applications with graphical interfaces

  • Solve all your security problems

  • What is a Docker namespace?

  • What is a Docker registry?

  • What is an entry point?

  • How to implement CI/CD in Docker?

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

  • What is a Docker swarm?

  • What are the docker commands for the following:

    • view running containers:docker container ls

    • command to run the container under a specific name

    • docker exec --workdir /tmp container-name pwd

    • command to export a docker

    • docker export

    • command to import an already existing docker image

    • docker import [options] file|URL|- [REPOSITORY[:TAG]]

    • commands to delete a container

    • docker rm <Container_ID>

    • command to remove all stopped containers, unused networks, build caches, and dangling images?

    • Docker prune command

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

  • 1. Bundling layers

  • 2. Avoid installation of unnecessary packages

  • 3.Clean up after install

  • 4. Use a .dockerignore