1.What is Docker and why is it used?
Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime.
2.What is a Docker image and how is it different from a Docker container?
The key difference between a Docker image vs a container is that a Docker image is a template that defines how a container will be realized. A Docker container is a runtime instance of a Docker image.
3.How do you create a Docker image and run a Docker container?
There are three way to create the Docker image.
A. Take image from Docker hub
B. Create image from Docker file
C. Create image from existing Docker containers
Now the steps for create the image and run the container.
root user+installed Docker+service start+create Dockerfile+now build the image from the Dockerfile +then create the container from that image.
4.What is a Dockerfile and how do you use it to create a Docker image?
Dockerfile is basically a text file.It contains some set of instruction.
Automation of Docker image creation.
To build image from the Dockerfile we need to use the Docker components so it help to create image and made the automation of the image.
There are some list of components for the different uses,
5.How can you inspect the contents of a Docker container and the changes made to a container while it was running?
By using "inspect command", we can the contents of a Docker container and the changes made to it.
6.How can you share a Docker image with others and pull an image from a Docker registry?
- Create a repository on any registry such as hub.docker.com
- Login to the repository on terminal using "docker login"
- The name of the docker image that you want to share and the repository should be the same. If not the create an alias of the image with the same name as of the repository using command "docker tag imagename repositoryname".
- Push the image on the repository using the command "docker push imagename".
- We can pull an image from a Docker registry by using "docker pull" command.
7.What are the different network modes available in Docker and how do you choose the right network mode for your application?
- Bridge networks-> it is used within a single host
- Overlay networks-> it is used for multi-host communication
- Macvlan networks-> it is used to connect Docker containers directly to host network interfaces
8.How can you mount a volume in a Docker container and share data between the host and container?
To mount a volume in a docker container, we use the command "docker run itd -v path", where path is the location of volume.
9.What is the difference between a Docker Compose file and a Dockerfile, and how are they used in deploying multi-container applications?
A Dockerfile is a text file that contains the commands that a user can execut to build an image.
Docker Compose is a tool for defining and running multi-container Docker applications.
10.How can you monitor the performance of a Docker container and diagnose issues with it?
We can monitor the performance of a docker container by executing the command "docker stats".
11. Components of Docker and its Brief Summary
It runs on the host O.S. It is responsible for running container to manages docker services and also it can communicate with the other doemen.
Docker client uses commands and rest API to communicate with the docker engine.
When a client runs any server command on the docker client terminal,the client terminal sends these docker command to the docker engine.
It is possible for docker client to communicate with more then one engine.
A Docker image contains set of instructions that are used to create a container.
A Docker registry is a storage system for Docker images.
Two types of the registry:
Docker containers are standardized,executable components that combine application source code with the operating system and dependencies that are required to run the code in any environment.
12.What is the difference between docker pause and unpause?
The docker pause command is used to suspend all processes in the specified containers.
The docker unpause command un-suspends all processes in the specified containers.
13.What is the differenet between docker stop and kill?
Docker stop command sends SIGTERM signal to running container process. It will stop the process however it takes a while to shutdown the container completely.
Docker kill command is kind of similar to docker stop command however it sends SIGKILL signal to our running container process. SIGKILL signal immediately shuts the container down without taking any pause
14.What is the difference between docker exec and attach?
The docker exec command is used to run a new command in a running container whereas docker attach command is used to attach the terminal's standard input, output, and error to a running container.
15.List of dockerfile instructions and its Brief Summary?
A.FROM: This command is used to create a base image such as an operating system, a programming language, etc.
B.RUN: To execute commends,it will create a layer in image.
D.COPY: copy files from the local system (Docker VM). We need
to provide source and the destination.
E.ADD: Similar to copy but It provides a feature yo download files from internet,also we extract file at docker image side.
F.WORKDIR: To set working directory for a container.
G.CMD: Execute commands but during container creation.
H.ENTRYPOINT: similar to CMD but it has higher priority over CMD,first commands will be executed by ENTRYPOINT only.
16.What is the differenet between CMD vs Entry?
- CMD: This command is used to run a docker container by specifying a default command that gets executed for all the containers of that image by default.
- Entrypoint: This instruction is used to configure the executables that will always run after the container is initiated.