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?
a) Programming Language
b) Text Editor
c) Containerization Platform
d) Web Server
Answer:
c) Containerization Platform
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?
a) docker build
b) docker pull
c) docker run
d) docker commit
Answer:
a) docker build
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?
a) Compiled source code
b) Docker images
c) Binary data
d) Instructions for building a Docker image
Answer:
d) Instructions for building a Docker image
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?
a) A running instance of a Docker image
b) A lightweight virtual machine
c) A storage volume
d) A service running on Docker Swarm
Answer:
a) A running instance of a Docker image
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?
a) docker list
b) docker show
c) docker ps
d) docker display
Answer:
c) docker ps
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?
a) docker get
b) docker fetch
c) docker pull
d) docker download
Answer:
c) docker pull
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?
a) docker exec
b) docker attach
c) docker run
d) docker enter
Answer:
a) docker exec
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?
a) docker rmi
b) docker remove
c) docker del
d) docker erase
Answer:
a) docker rmi
Explanation:
The docker rmi command removes one or more Docker images from your local machine.
9. What is Docker Compose?
a) A scripting language for Docker
b) A continuous integration tool for Docker
c) A tool for defining and running multi-container Docker applications
d) A Docker CLI plugin
Answer:
c) A tool for defining and running multi-container Docker applications
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?
a) Kubernetes Hub
b) Container Store
c) Docker Hub
d) Image Hub
Answer:
c) Docker Hub
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?
a) To provide a graphical visualization of containers
b) To build and run containers
c) To manage databases inside containers
d) To interface with Kubernetes
Answer:
b) To build and run containers
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?
a) docker login
b) docker auth
c) docker sign-in
d) docker connect
Answer:
a) docker login
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?
a) Deletes the container
b) Displays detailed information
c) Detaches the container (runs in the background)
d) Downloads the latest image
Answer:
c) Detaches the container (runs in the background)
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?
a) Use --filename option
b) Use --source option
c) Use --file option
d) Use --dockerfile option
Answer:
c) Use --file option
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?
a) A public network accessible from outside
b) A private network segment created for a specific container
c) A way to connect multiple containers to the internet
d) A network connecting containers to each other on the same host
Answer:
d) A network connecting containers to each other on the same host
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?
a) Using --volumes-from
b) Using --share-storage
c) Using --link
d) Using --connect-volumes
Answer:
a) Using --volumes-from
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?
a) aufs
b) btrfs
c) zfs
d) ntfs
Answer:
d) ntfs
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?
a) To list all images to be pulled from the Docker Hub
b) To specify commands to run inside a container
c) To prevent certain files and directories from being copied into an image
d) To provide metadata about a Docker image
Answer:
c) To prevent certain files and directories from being copied into an image
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?
a) docker inspect
b) docker details
c) docker history
d) docker layers
Answer:
c) docker history
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?
a) Specifies the base images for services
b) Specifies the build context for services
c) Specifies the order in which services are started
d) Specifies the network links between services
Answer:
c) Specifies the order in which services are started
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?
a) Image version management
b) Multi-host container orchestration
c) Container storage optimization
d) Automated container build pipeline
Answer:
b) Multi-host container orchestration
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?
a) docker swarm init
b) docker swarm start
c) docker swarm create
d) docker swarm manager
Answer:
a) docker swarm init
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?
a) bridge
b) host
c) overlay
d) transit
Answer:
d) transit
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?
a) docker logs CONTAINER_ID/NAME
b) docker show-logs CONTAINER_ID/NAME
c) docker view CONTAINER_ID/NAME
d) docker inspect CONTAINER_ID/NAME
Answer:
a) docker logs CONTAINER_ID/NAME
Explanation:
The docker logs command allows you to view the logs of a running container.
25. What command creates a new volume in Docker?
a) docker volume create
b) docker create volume
c) docker volume new
d) docker new volume
Answer:
a) docker volume create
Explanation:
The docker volume create command is used to create a new volume.
26. How can you inspect the details of a Docker network?
a) docker network view NETWORK_NAME
b) docker network show NETWORK_NAME
c) docker network detail NETWORK_NAME
d) docker network inspect NETWORK_NAME
Answer:
d) docker network inspect NETWORK_NAME
Explanation:
The docker network inspect command is used to display detailed information about a network.
27. Which command stops a running Docker container?
a) docker kill CONTAINER_ID/NAME
b) docker pause CONTAINER_ID/NAME
c) docker halt CONTAINER_ID/NAME
d) docker stop CONTAINER_ID/NAME
Answer:
d) docker stop CONTAINER_ID/NAME
Explanation:
The docker stop command stops a running container.
28. How can you see all images available on your local machine?
a) docker show images
b) docker list images
c) docker images
d) docker img
Answer:
c) docker images
Explanation:
The docker images command lists all images available locally.
29. How do you remove a Docker volume?
a) docker remove-volume VOLUME_NAME
b) docker rmvol VOLUME_NAME
c) docker volume rm VOLUME_NAME
d) docker delete VOLUME_NAME
Answer:
c) docker volume rm VOLUME_NAME
Explanation:
The docker volume rm command is used to remove a volume.
30. Which command connects a container to a Docker network?
a) docker network connect NETWORK_NAME CONTAINER_NAME
b) docker connect NETWORK_NAME CONTAINER_NAME
c) docker attach NETWORK_NAME CONTAINER_NAME
d) docker link NETWORK_NAME CONTAINER_NAME
Answer:
a) docker network connect NETWORK_NAME CONTAINER_NAME
Explanation:
The docker network connect command connects a running container to a Docker network.
Comments
Post a Comment
Leave Comment