Docker is a platform that simplifies the development, deployment, and management of applications inside containers. This blog post aims to cover the essential concepts of Docker through a set of 30 multiple-choice questions. Each question includes an answer and an explanation to help you understand the fundamental aspects of Docker better.
1. What is Docker?
Answer:
Explanation:
Docker is a platform designed to make it easier to create, deploy, and run applications using containers. It's not a programming language, text editor, or web server.
2. Which command is used to create a new Docker image?
Answer:
Explanation:
The docker build command is used to build a new image from a Dockerfile and a "context". The context is the set of files in a specified directory or URLs that the image is built from.
3. What does the Dockerfile contain?
Answer:
Explanation:
A Dockerfile is a text file that contains the instructions for how to build a Docker image from a base image.
4. What is a Docker container?
Answer:
Explanation:
A Docker container is a running instance of a Docker image, which is an executable package that includes everything needed to run a piece of software, including the code, libraries, environment variables, and config files.
5. What command is used to list all running Docker containers?
Answer:
Explanation:
The docker ps command lists all running Docker containers, along with various details like container ID, image name, creation time, and so on.
6. Which command pulls an image from Docker Hub?
Answer:
Explanation:
The docker pull command is used to pull or download a Docker image from a registry like Docker Hub.
7. How can you run a command inside an existing Docker container?
Answer:
Explanation:
The docker exec command allows you to run commands inside an existing container. For example, docker exec -it container_id /bin/bash would open a bash shell inside the container with ID container_id.
8. Which command is used to remove a Docker image?
Answer:
Explanation:
The docker rmi command removes one or more Docker images from your local machine.
9. What is Docker Compose?
Answer:
Explanation:
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you define the services, networks, and volumes in a single docker-compose.yml file and then use docker-compose up to start the entire application stack.
10. Which of the following is the default registry used by Docker?
Answer:
Explanation:
Docker Hub is the default public registry where Docker images are stored and shared. You can pull and push images from and to Docker Hub.
11. What is the primary purpose of the Docker Engine?
Answer:
Explanation:
Docker Engine is the core of Docker. It is responsible for building, running, and managing containers.
12. Which of the following commands logs you into Docker Hub from the CLI?
Answer:
Explanation:
The docker login command allows users to log into Docker Hub or any other Docker registry from the command-line interface.
13. What does the -d flag do in the docker run command?
Answer:
Explanation:
When using -d with the docker run command, the container starts in detached mode, which means it runs in the background and does not attach to the current terminal session.
14. How do you specify a Dockerfile other than the default "Dockerfile" during the build process?
Answer:
Explanation:
The --file or -f option allows users to specify a different Dockerfile than the default one. For example, docker build -f MyDockerfile ..
15. In Docker, what is a bridge network?
Answer:
Explanation:
The default bridge network in Docker allows containers to communicate with each other on the same host machine, but it does not allow for direct external access.
16. How can you share storage volumes between containers?
Answer:
Explanation:
The --volumes-from option allows a container to mount the volumes from another container, enabling data sharing between containers.
17. Which of the following is not a valid storage driver for Docker?
Answer:
Explanation:
NTFS is a filesystem used by Windows, but it's not a storage driver for Docker. Docker supports storage drivers like aufs, btrfs, zfs, and others depending on the platform.
18. What is the primary function of the .dockerignore file?
Answer:
Explanation:
The .dockerignore file allows users to exclude files and directories from being copied to the image during the build process, much like .gitignore does for git repositories.
19. Which Docker command shows the history and intermediate layers of an image?
Answer:
Explanation:
The docker history command shows the history of an image, displaying the layers and the commands that were used to create them.
20. In a docker-compose.yml file, what is the function of the depends_on key?
Answer:
Explanation:
In a docker-compose.yml file, the depends_on key indicates the order in which services should be started. A service with a depends_on key will not start until the services it depends on have been started.
21. What is the primary purpose of Docker Swarm?
Answer:
Explanation:
Docker Swarm is a native clustering and orchestration tool for Docker. It allows you to create and manage a swarm of Docker nodes and orchestrate services across multiple hosts.
22. What command initializes a node as a Docker Swarm manager?
Answer:
Explanation:
The docker swarm init command initializes the current node as a Docker Swarm manager, which manages the infrastructure of a swarm.
23. Which of the following is not a Docker network type?
Answer:
Explanation:
Docker supports several network types, including bridge, host, and overlay. "transit" is not one of the built-in network types in Docker.
24. Which command is used to view the logs of a running Docker container?
Answer:
Explanation:
The docker logs command allows you to view the logs of a running container.
25. What command creates a new volume in Docker?
Answer:
Explanation:
The docker volume create command is used to create a new volume.
26. How can you inspect the details of a Docker network?
Answer:
Explanation:
The docker network inspect command is used to display detailed information about a network.
27. Which command stops a running Docker container?
Answer:
Explanation:
The docker stop command stops a running container.
28. How can you see all images available on your local machine?
Answer:
Explanation:
The docker images command lists all images available locally.
29. How do you remove a Docker volume?
Answer:
Explanation:
The docker volume rm command is used to remove a volume.
30. Which command connects a container to a Docker network?
Answer:
Explanation:
The docker network connect command connects a running container to a Docker network.
Comments
Post a Comment
Leave Comment