What is Docker?
Docker is a containerization platform which packages your application and all its dependencies together in the form of containers so as to ensure that your application works seamlessly in any environment be it development or test or production.
[dt_sc_button type=”type1″ link=”http://www.interviewgig.com/discussion-room/post-a-question/” size=”large” bgcolor=”#7ed640″ textcolor=”#ffffff” target=”_blank” timeline_button=”no”]Post a Question[/dt_sc_button]
What is Docker image?
Docker image is the source of Docker container. In other words, Docker images are used to create containers. Images are created with the build command, and they’ll produce a container when started with run. Images are stored in a Docker registry such as registry.hub.docker.com because they can become quite large, images are designed to be composed of layers of other images, allowing a minimal amount of data to be sent when transferring images over the network.
How is Docker different from other container technologies?
Docker containers are easy to deploy in a cloud. It can get more applications running on the same hardware than other technologies, it makes it easy for developers to quickly create, ready-to-run containerized applications and it makes managing and deploying applications much easier. You can even share containers with your applications.
What is Docker Machine?
We can use Docker Machine to install Docker Engine on virtual hosts. It also provides commands to manage virtual hosts.
Some of the popular Docker machine commands enable us to start, stop, inspect and restart a managed host.
Docker Machine provides a Command Line Interface (CLI), which is very useful in managing multiple hosts.
Why do we use Docker Machine?
There are two main uses of Docker Machine:
Old Desktop: If we have an old desktop and we want to run Docker then we use Docker Machine to run Docker. It is like installing a virtual machine on an old hardware system to run Docker engine.
Remote Hosts: Docker Machine is also used to provision Docker hosts on remote systems. By using Docker Machine, you can install Docker Engine on remote hosts and configure clients on them.
What is Docker Hub?
Docker Hub is a cloud-based registry. We can use Docker Hub to link code repositories. We can even build images and store them in Docker Hub. It also provides links to Docker Cloud to deploy the images to our hosts.
Docker Hub is a central repository for container image discovery, distribution, change management, workflow automation and team collaboration.
What are the main features of Docker Hub?
Docker Hub provides following main features:
Image Repositories: In Docker Hub we can push, pull, find and manage Docker Images. It is a big library that has images from community, official as well as private sources.
Automated Builds: We can use Docker Hub to create new images by making changes to source code repository of the image.
Webhooks: With Webhooks in Docker Hub we can trigger actions that can create and build new images by pushing a change to repository.
Github/Bitbucket integration: Docker Hub also provides integration with Github and Bitbucket systems.
What is Docker Entrypoint?
- We use Docker Entrypoint to set the starting point for a command in a Docker Image.
- We can use the entrypoint as a command for running an Image in the container.
What is Docker Swarm?
Docker Swarm is native clustering for Docker. It turns a pool of Docker hosts into a single, virtual Docker host. Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.
What are the features of Docker Swarm?
Some of the key features of Docker Swarm are as follows:
Compatible: Docker Swarm is compatible with standard Docker API.
High Scalability: Swarm can scale up to as much as 1000 nodes and 50000 containers. There is almost no performance degradation at this scale in Docker Swarm.
Networking: Swarm comes with support for Docker Networking.
High Availability: We can create a highly available system with Docker Swarm. It allows use to create multiple master nodes so that in case of a failure, another node can take over.
Node Discovery: In Docker Swarm, we can add more nodes and the new nodes can be found with any discovery service like etcd or zookeeper etc.
What are the three main steps of Docker Compose?
Three main steps of Docker Compose are as follows:
Environment: We first define the environment of our application with a Dockerfile. It can be used to recreate the environment at a later point of time.
Services: Then we define the services that make our app in docker-compose.yml. By using this file we can define how these services can be run together in an environment.
Run: The last step is to run the Docker Container. We use docker-compose up to start and run the application.
What are the common use cases of Docker?
Some of the common use cases of Docker are as follows:
Setting up Development Environment: We can use Docker to set the development environment with the applications on which our code is dependent.
Testing Automation Setup: Docker can also help in creating the Testing Automation setup. We can setup different services and apps with Docker to create the automation testing environment.
Production Deployment: Docker also helps in implementing the Production deployment for an application. We can use it to create the exact environment and process that will be used for doing the production deployment.
What are the main features of Docker-compose?
Some of the main features of Docker-compose are as follows:
Multiple environments on same Host: We can use it to create multiple environments on the same host server.
Preserve Volume Data on Container Creation: Docker compose also preserves the volume data when we create a container.
Recreate the changed Containers: We can also use compose to recreate the changed containers.
Variables in Compose file: Docker compose also supports variables in compose file. In this way, we can create variations of our containers.
What is the most popular use of Docker?
The most popular use of Docker is in build pipeline. With the use of Docker it is much easier to automate the development to deployment process in build pipeline.
We use Docker for the complete build flow from development work, test run and deployment to production environment.
What is the difference between Docker commands: up, run and start?
We have up and start commands in docker-compose. The run command is in docker.
Up: We use this command to build, create, start or restart all the services in a docker-compose.yml file. It also attaches to containers for a service.This command can also start linked services.
Run: We use this command for adhoc requests. It just starts the service that we specifically want to start. We generally use it run specific tests or any administrative tasks.
Start: This command is used to start the container that were previously created but are not currently running. This command does not create new containers.
For More:
How will you take backup of Docker container volumes in AWS S3?
We can use a utility named Dockup provided by Docker Cloud to take backup of Docker container volumes in S3.
What is the basic architecture behind Docker?
- Docker is built on client server model. Docker server is used to run the images. We use Docker client to communicate with Docker server.
- Clients tell Docker server via commands what to do.
- Additionally, there is a Registry that stores Docker Images. Docker Server can directly contact Registry to download images.
Why do we use Docker on top of a virtual machine?
Generally, we use Docker on top of a virtual machine to ensure isolation of the application. On a virtual machine, we can get the advantage of security provided by hypervisor. We can implement different security levels on a virtual machine. And Docker can make use of this to run the application at different security levels.
What is Build cache in Docker?
When we build an Image, Docker will process each line in Dockerfile. It will execute the commands on each line in the order that is mentioned in the file. But at each line, before running any command, Docker will check if there is already an existing image in its cache that can be reused rather than creating a new image.
This method of using cache in Docker is called Build cache in Docker.
We can also specify the option –no-cache=true to let Docker know that we do not want to use cache for Images. With this option, Docker will create all new images.
What are the main benefits of using Docker?
Docker is a very powerful tool. Some of the main benefits of using Docker are as follows:
Utilize Developer Skills: With Docker we maximize the use of Developer skills. With Docker there is less need of build or release engineers. Same Developer can create software and wrap it in one single file.
Standard Application Image: Docker based system allows us to bundle the application software and Operating system files in a single Application Image that can be deployed independently.
Uniform deployment: With Docker we can create one package of our software and deploy it on different platforms seamlessly.
How will you Setup a Docker Locally?
- Download a latest Docker edition and the Docker Toolbox
- Make sure to Enable Hyper-V Windows Features
- Install the Extension Pack and Run the Setup
Can you explain Docker Container?
A container is the basic unit of software that holds the code and all its dependencies, in order to make the application run smoothly, quickly and reliably from one computing ecosystem to another. A Docker container may be created using a Docker image. It is an executable package of the software, which holds everything that is required to run an application, which are system tools, libraries, code, runtime, and settings.
What’s Lifecycle of Docker Container?
- Create container
- Run container
- Pause container
- Unpause container
- Start container
- Stop container
- Restart container
- Kill container
- Destroy container
Can you explain the use of Docker system prune?
Prune is one of the most useful commands in Docker. Its used to Remove all unused containers, networks, images, and optionally, volumes.
docker system prune [OPTIONS]
Know more about docker system prune @ See more..
How will you use docker save command?
We can docker save command to Save one or more images to a tar archive (streamed to STDOUT by default)
docker save [OPTIONS] IMAGE [IMAGE...]
Know more about docker save @ See more..
How will you use docker load command?
We can docker load command to Load an image or repository from a tar archive from a file or STDIN. It restores both images and tags.
docker load [OPTIONS]
Know more about docker load @ See more..
How will you use create docker swarm?
We can create docker swarm by using bellow command
$ docker swarm init –advertise-addr <MANAGER-IP>
Know more about docker swarm creation @ See more..
How will you start a docker container?
To start one or more stopped docker containers, you can use the docker start command.
$ docker start [OPTIONS] CONTAINER [CONTAINER...]
How will you stop a docker container?
To stop one or more running Docker containers, you can use the docker stop command.
$ docker stop [OPTIONS] CONTAINER [CONTAINER...]
Can you name some of the docker commands?
docker run : Create a new container and start it
docker create : Create a container from an image
docker build : Build an image from a Dockerfile
docker config : Manage Docker configs
docker login : Log in to a Docker registry
docker version : Show the Docker version information
For more info on docker commands @ See more..
How will you identify the status of a Docker Container?
By using docker ps -a we can list containers with the respective status on the host
How will you list containers?
Bellow commands will help us to list containers in docker
docker ps -a //To show all containers
docker ps //To show only running containers
docker ps -l //To show the latest created container
docker ps -n=-1 //To show n last created containers
docker ps -s //To display total file sizes
docker ps -q //To display container IDs
docker ps -f //To display Filter output based on conditions provided
Know more about docker containers @ See more..
How will you Login to a self-hosted registry?
We can login to self-hosted registry, we need to mention the server name
$ docker login localhost:8080
How will you delete an image from the local storage system?
To Remove one or more images, use docker rmi command
docker rmi [OPTIONS] IMAGE [IMAGE...]
How can I use JSON instead of YAML for compose file?
You can use JSON file with compose, by specifying the JSON filename
$ docker-compose -f docker-compose.json up
How will you Check for Docker Client and Docker Server version?
We can check the docker version using the command docker version [options]
$ docker version --format '{{.Server.Version}}'
Can a container restart by itself?
No, it’s not possible for a container to restart by itself
Is it possible for a container to restart by itself?
Yes, it is possible. Docker defines certain policies to restart the container. These are Off: container won’t be restarted if it stops or fails,
- On-failure: container restarts only when a failure that occurred is not due to the user,
- Unless-stopped: container restarts only when a user executes the command to stop it,
- Always: the container is always restarted irrespective of error or other issues.
$ docker run -dit — restart [unless-stopped|off|on-failure|always] [CONTAINER]
How will you disable auto-restart on a container?
We can use the –restart=unless-stopped option
docker update –restart=no my-container
How will you check the disk usage of all running Docker containers?
By using docker system df we can get total size of all images and size of all containers, local volumes size and the cache.
How will you push a docker image to a private repository?
good