Table of contents
Questions
What is the Difference between an Image, Container, and Engine?
An image is a packaged set of files that contains everything needed to run an application, a container is a runtime instance of an image, and an engine is software that manages containers and images.
What is the Difference between the Docker command COPY vs ADD?
The
COPY
the command can only copy local files and directories from the host system to a container. In contrast, ADD
the command can also copy remote files and URLs, and it can also extract tar files automatically during the copy processWhat is the Difference between the Docker command CMD vs RUN?
RUN
the command is used to execute a command during the Docker build process to install or configure software in the image, while the CMD
command is used to set the default command that will be executed when the container is started.How Will you reduce the size of the Docker image?
Use a smaller base image: Choose a smaller base image for your Dockerfile, such as Alpine Linux or BusyBox, instead of a full-featured distribution like Ubuntu or CentOS. Remove unnecessary files: Remove unnecessary files, such as log files, temporary files, and cache, from the image. You can use the RUN command to delete files after they are no longer needed. Compress files: Compress files, such as configuration files or static assets, to reduce the image size. You can use tools like tar or gzip to compress the files and decompress them during the container runtime.
Why and when to use Docker?
In terms of when to use Docker, it's a good fit for applications that are complex and have multiple dependencies, such as microservices-based architectures. It's also useful for projects with multiple developers or teams working on the same codebase, as Docker provides a consistent environment for everyone to work in. Additionally, if you need to run multiple applications on the same server or need to scale your application quickly, Docker can help simplify the process.
Explain the Docker components and how they interact with each other.
The main Docker components are:- Docker daemon, Docker client, Docker registry, Docker image, and Docker container. When a user wants to create and run a container, they use the Docker client to send a request to the Docker daemon. The Docker daemon then searches for the requested image in the local image cache or the Docker registry, and if it's not found, it downloads the image from the registry. Once the image is available, the Docker daemon creates a container based on that image, assigns it a unique identifier, and starts it. The Docker client can then interact with the container, sending commands to start, stop, and manage its lifecycle.
Explain the terminology: Docker Compose, Docker File, Docker Image, Docker Container?
Docker Compose is used to manage multi-container Docker applications, while a Dockerfile is used to define the instructions for building a Docker image. A Docker image is a read-only template that contains everything needed to run an application, and a Docker container is a running instance of a Docker image.
In what real scenarios have you used Docker?
Docker is commonly used in a variety of scenarios, including microservices architecture, development and testing, continuous integration and deployment, and cloud computing.
Docker vs Hypervisor?
Docker and hypervisors are both technologies used for virtualization, but they operate in different ways and are suited to different use cases. Docker is designed for lightweight, portable containers, while hypervisors provide complete isolation between virtual machines.
What are the advantages and disadvantages of using docker?
Docker has several advantages Portability, Consistency, Efficiency, Scalability, and Collaboration, but some potential drawbacks are Security, Debugging, Complexity, and Resource usage.
What is a Docker namespace?
A Docker namespace is a mechanism for providing isolation and security between containers and the host machine. Docker uses namespaces to provide a separate instance of various system resources to each container, which makes each container think that it has its own isolated environment. There are several types of namespaces used by Docker, including PID namespace, Network namespace, Mount namespace, and Inter-process communication namespace.
What is a Docker registry?
A Docker registry is a central repository where Docker images are stored, managed, and distributed. It serves as a hub for developers to share and distribute Docker images with others, either publicly or privately.
What is an entry point?
The entry point can be defined in a Dockerfile using the
ENTRYPOINT
instruction and it is typically used in combination with the CMD
instruction to provide default arguments or parameters to the command specified in the entry point script.How to implement CI/CD in Docker?
1. Set up a source code repository and version control system, such as Git, to store your application code. 2. Create a Dockerfile that specifies the dependencies and configuration for your application, including the application code, in the form of a Docker image. 3. Configure a CI/CD pipeline tool, such as Jenkins, Travis CI, or CircleCI, to build and test the Docker image when changes are made to the code repository. 4. Deploy the Docker image to a registry, such as Docker Hub, or a private registry like Amazon Elastic Container Registry (ECR) or Google Container Registry (GCR). 5. Use a container orchestration tool, such as Kubernetes or Docker Swarm, to automate the deployment and scaling of the Docker containers based on the updated Docker image. 6. Monitor and manage the Docker containers in production to ensure availability, performance, and security.
Will data on the container be lost when the docker container exits?
In Docker, by default, any data that was written inside the container is not preserved when the container is stopped or removed. This means that if you start a container, write some files or make some changes inside the container and then stop or remove it, any changes made inside the container will be lost.
What is a Docker swarm?
Docker Swarm is a container orchestration platform provided by Docker. It allows you to create and manage a cluster of Docker nodes, also known as a swarm, to deploy and scale your applications across multiple hosts. Docker Swarm provides a high level of availability and fault tolerance for your applications by automatically distributing containers across the nodes in the swarm.
What are the docker commands for the following: 1. view running containers 2. command to run the container under a specific name 3. command to export a docker 4. command to import an already existing docker image 5. commands to delete a container 6. command to remove all stopped containers, unused networks, build caches, and dangling images?
1. docker ps 2. docker run --name mycontainer image-name 3. docker export container-id > container.tar 4. docker import container.tar repository-name:tag 5. docker rm container-id 6. docker system prune
What are the common docker practices to reduce the size of Docker Image?
1 Use a smaller base image 2 Remove unnecessary files 3 Use multi-stage builds 4 Minimize layers 5 Use caching effectively 6 Remove unnecessary dependencies
Happy Learning :)
Thank you ๐
ย