Docker Basic quiz Quiz

Beginner 35 questions

Very important docker quiz. Test your understanding of Docker fundamentals, images, containers, commands, and best practices.

Practice questions & answers

1

What is Docker primarily used for?

  • 1. Containerizing applications
  • 2. Managing databases only
  • 3. Writing source code
  • 4. Creating operating systems
Show explanation

Docker packages applications and their dependencies into containers. The other options describe activities Docker is not primarily designed for.

2

What is a Docker container?

  • 1. A running instance of an image
  • 2. A Docker configuration file
  • 3. A physical server
  • 4. A programming language
Show explanation

A container is a running instance created from a Docker image. It provides an isolated environment for applications.

3

What is a Docker image?

  • 1. A blueprint used to create containers
  • 2. A running application
  • 3. A network protocol
  • 4. A storage device
Show explanation

A Docker image is a read-only template containing application code and dependencies. Containers are created from images.

4

Which command lists running Docker containers?

  • 1. docker ps
  • 2. docker images
  • 3. docker build
  • 4. docker pull
Show explanation

docker ps shows running containers. docker images lists images, while build and pull perform different tasks.

5

Which command displays Docker images stored locally?

  • 1. docker images
  • 2. docker logs
  • 3. docker run
  • 4. docker exec
Show explanation

docker images lists locally available images. The other commands are used for logs, starting containers, or executing commands.

6

Which file is used to define instructions for building a Docker image?

  • 1. Dockerfile
  • 2. docker-compose.yml
  • 3. requirements.txt
  • 4. config.ini
Show explanation

A Dockerfile contains instructions for building an image. Other files serve different purposes.

7

Which command builds an image from a Dockerfile in the current directory?

  • 1. docker build .
  • 2. docker start .
  • 3. docker create .
  • 4. docker copy .
Show explanation

docker build . uses the current directory as the build context. The other commands do not build images.

8

What does the command docker pull do?

  • 1. Downloads an image from a registry
  • 2. Deletes an image
  • 3. Starts a container
  • 4. Builds an image
Show explanation

docker pull retrieves an image from a registry such as Docker Hub. It does not build or run containers.

9

Which command starts a new container from an image?

  • 1. docker run
  • 2. docker inspect
  • 3. docker volume
  • 4. docker tag
Show explanation

docker run creates and starts a container from an image. The other commands perform different management tasks.

10

What is Docker Hub?

  • 1. A public image registry
  • 2. A container runtime
  • 3. A Linux distribution
  • 4. A text editor
Show explanation

Docker Hub is a popular registry for storing and sharing Docker images. It is not a runtime or operating system.

11

Which command stops a running container?

  • 1. docker stop
  • 2. docker pause
  • 3. docker rm
  • 4. docker build
Show explanation

docker stop gracefully stops a running container. docker rm removes containers and build creates images.

12

Which command removes a container?

  • 1. docker rm
  • 2. docker ps
  • 3. docker top
  • 4. docker tag
Show explanation

docker rm removes containers that are no longer needed. The other commands provide information or tagging functionality.

13

What is the purpose of the EXPOSE instruction in a Dockerfile?

  • 1. Document which port the application uses
  • 2. Start the application
  • 3. Create a volume
  • 4. Install packages
Show explanation

EXPOSE indicates the intended network port for the application. It does not actually publish the port by itself.

14

Which Dockerfile instruction specifies the base image?

  • 1. FROM
  • 2. RUN
  • 3. CMD
  • 4. COPY
Show explanation

FROM defines the base image used for building. Most Dockerfiles begin with a FROM instruction.

15

Which instruction copies files from the host into an image during build?

  • 1. COPY
  • 2. FROM
  • 3. CMD
  • 4. ENTRYPOINT
Show explanation

COPY transfers files into the image. FROM selects a base image and CMD defines default commands.

16

What does the RUN instruction do in a Dockerfile?

  • 1. Executes commands during image build
  • 2. Starts the container
  • 3. Maps ports
  • 4. Creates networks
Show explanation

RUN executes commands while building the image, often to install software or configure the environment.

17

What is the main purpose of Docker volumes?

  • 1. Persist data outside containers
  • 2. Increase CPU speed
  • 3. Replace images
  • 4. Create users
Show explanation

Volumes store data independently of container lifecycles, allowing data to survive container removal.

18

Which flag runs a container in detached mode?

  • 1. -d
  • 2. -p
  • 3. -it
  • 4. --rm
Show explanation

The -d flag starts a container in the background. Other flags are used for ports, interactive mode, or cleanup.

19

Which option is commonly used to map a host port to a container port?

  • 1. -p
  • 2. -d
  • 3. -v
  • 4. -e
Show explanation

The -p flag publishes container ports to the host. This allows external access to services running in containers.

20

What does docker logs display?

  • 1. Container output and logs
  • 2. Image layers
  • 3. Network configuration
  • 4. Volume contents
Show explanation

docker logs shows stdout and stderr generated by a container, helping with troubleshooting.

21

Which command allows you to execute a command inside a running container?

  • 1. docker exec
  • 2. docker pull
  • 3. docker save
  • 4. docker commit
Show explanation

docker exec runs commands inside an already running container. It is commonly used for debugging.

22

What is the benefit of using containers?

  • 1. Consistent environments across systems
  • 2. Unlimited storage
  • 3. Automatic coding
  • 4. Faster internet
Show explanation

Containers package applications and dependencies together, reducing environment-related issues across systems.

23

Which command shows detailed information about a container?

  • 1. docker inspect
  • 2. docker search
  • 3. docker cp
  • 4. docker rename
Show explanation

docker inspect provides detailed JSON information about Docker objects such as containers and images.

24

What does the -it option commonly provide when running a container?

  • 1. Interactive terminal access
  • 2. Image tagging
  • 3. Port mapping
  • 4. Automatic restart
Show explanation

-i keeps STDIN open and -t allocates a terminal, enabling interactive shell sessions.

25

Which command downloads an Ubuntu image and starts a container?

  • 1. docker run ubuntu
  • 2. docker logs ubuntu
  • 3. docker inspect ubuntu
  • 4. docker volume ubuntu
Show explanation

docker run automatically pulls the image if needed and starts a container from it.

26

What is a Docker registry?

  • 1. A service that stores and distributes images
  • 2. A running container
  • 3. A Linux kernel module
  • 4. A volume driver
Show explanation

Registries store Docker images and make them available for download and sharing.

27

Which command removes an image from the local system?

  • 1. docker rmi
  • 2. docker stop
  • 3. docker exec
  • 4. docker network
Show explanation

docker rmi removes images from local storage. It does not affect running containers directly.

28

What is the purpose of the CMD instruction in a Dockerfile?

  • 1. Define the default command for a container
  • 2. Build the image
  • 3. Expose a port
  • 4. Copy files
Show explanation

CMD specifies the default command executed when a container starts unless overridden.

29

Why is it generally recommended to use official images when possible?

  • 1. They are maintained and widely trusted
  • 2. They consume no disk space
  • 3. They never need updates
  • 4. They run only on Linux
Show explanation

Official images are typically maintained, documented, and reviewed, making them a safer starting point.

30

Which command lists all containers, including stopped ones?

  • 1. docker ps -a
  • 2. docker ps
  • 3. docker images
  • 4. docker stats
Show explanation

docker ps -a displays both running and stopped containers. docker ps shows only running containers.

31

What does the -v option commonly do when running a container?

  • 1. Mount a volume or directory
  • 2. Display version information
  • 3. Validate an image
  • 4. View logs
Show explanation

The -v option is commonly used to mount host directories or Docker volumes into containers.

32

Which environment variable flag can be used with docker run?

  • 1. -e
  • 2. -p
  • 3. -d
  • 4. -a
Show explanation

The -e flag passes environment variables into a container. This is useful for configuration.

33

What happens when a container's main process exits?

  • 1. The container stops
  • 2. The image is deleted
  • 3. The host shuts down
  • 4. All volumes are removed
Show explanation

A container's lifecycle is tied to its main process. When that process exits, the container stops.

34

Which command can be used to view resource usage statistics of running containers?

  • 1. docker stats
  • 2. docker push
  • 3. docker export
  • 4. docker attach
Show explanation

docker stats provides live CPU, memory, network, and I/O usage information for containers.

35

What is a key best practice when building Docker images?

  • 1. Keep images as small as practical
  • 2. Install unnecessary packages
  • 3. Run everything as root when possible
  • 4. Store large backups in the image
Show explanation

Smaller images build faster, transfer faster, and generally reduce security and maintenance overhead. The other options are poor practices.