Containers Questions with Answers

20 practice questions on Containers (Cloud Computing) with answers and step-by-step solutions. Try 10 samples below, then practise all 20 free in the AptiNest app.

Sample questions

Question 1Easy

What does a container package together?

  1. Only the raw source code of the app
  2. An app with its libraries and dependencies
  3. A full OS kernel together with firmware
  4. Physical hardware drivers for the host

Answer: B. An app with its libraries and dependencies

Explanation

Containers bundle the app with everything it needs in user space, so it runs the same across environments.

Step-by-step solution

  1. A container bundles the app.
  2. It includes the libraries and dependencies it needs in user space.
  3. It does not include a kernel.

Why the other options are wrong

  • A. Source code alone cannot run without dependencies.
  • C. Containers share the host kernel.
  • D. Hardware drivers belong to the host.

Question 2Easy

Which is a key advantage of containers?

  1. They cannot be automated with scripts
  2. They always need more memory than VMs
  3. They each require a separate kernel
  4. Consistency across environments

Answer: D. Consistency across environments

Explanation

Bundling dependencies removes "works on my machine" problems between dev, test and production.

Step-by-step solution

  1. A container bundles the app with its dependencies.
  2. The same image runs in dev, test and production.
  3. Environments behave consistently.

Why the other options are wrong

  • A. Containers are highly scriptable.
  • B. Containers usually need less memory than VMs.
  • C. Containers share the host kernel.

Tip: Build once, run anywhere (with the same kernel type).

Question 3Easy

What is the main purpose of a container volume?

  1. Exposing a container port to the internet
  2. Increasing the CPU speed of a container
  3. Persisting data beyond a container's life
  4. Compressing the image to save space

Answer: C. Persisting data beyond a container's life

Explanation

Volumes are managed storage mounted into containers so data survives restarts and replacement.

Step-by-step solution

  1. A volume is storage managed outside the container's writable layer.
  2. It is mounted into the container at a path.
  3. Data in it survives restarts and container replacement.

Why the other options are wrong

  • A. Exposing ports is done with port mapping.
  • B. Volumes do not change CPU speed.
  • D. Volumes do not compress images.

Question 4Easy

What is the difference between a container image and a container?

  1. They are two names for exactly the same thing
  2. A container is the template and an image is the running copy
  3. An image is a virtual machine and a container is a disk
  4. An image is a template; a container is a running instance

Answer: D. An image is a template; a container is a running instance

Explanation

You build an image once and can start many containers from it.

Step-by-step solution

  1. An image is a read-only template.
  2. A container is a running instance created from it.
  3. One image can start many containers.

Why the other options are wrong

  • A. They are different things.
  • B. This reverses them.
  • C. Neither is a VM or a disk.

Question 5Medium

By default, data written inside a container's writable layer:

  1. Is automatically backed up to the cloud
  2. Is lost when the container is removed
  3. Is shared with every other running container
  4. Is written permanently back into the image

Answer: B. Is lost when the container is removed

Explanation

Containers are ephemeral; persistent data should go to volumes or external storage.

Step-by-step solution

  1. A container has a thin writable layer on top of the image.
  2. When the container is removed, that layer is deleted.
  3. Data written there is lost.

Why the other options are wrong

  • A. No automatic backup exists.
  • C. Each container has its own writable layer.
  • D. Images are read-only and unchanged.

Tip: Container = disposable; volume = persistent.

Question 6Medium

A container image's base image is:

  1. An image that has no file system
  2. The image that later build steps add layers on top of
  3. The largest image stored in the registry
  4. The final image deployed to production

Answer: B. The image that later build steps add layers on top of

Explanation

Every Dockerfile starts FROM a base image, such as a minimal OS or language runtime image.

Step-by-step solution

  1. Every Dockerfile starts with FROM.
  2. The image named there is the base image.
  3. Later steps add layers on top of it.

Why the other options are wrong

  • A. Base images do have file systems.
  • C. Size has nothing to do with being a base.
  • D. That is the final image.

Tip: Smaller base = smaller attack surface.

Question 7Medium

What does mapping a port such as 8080:80 typically do when running a container?

  1. Blocks all traffic on both of these ports
  2. Forwards container port 8080 to host port 80
  3. Forwards host port 8080 to container port 80
  4. Opens a range of 80 ports starting at 8080

Answer: C. Forwards host port 8080 to container port 80

Explanation

The format is host_port:container_port.

Step-by-step solution

  1. Port mapping format is host_port:container_port.
  2. 8080:80 means traffic to host port 8080 goes to container port 80.

Why the other options are wrong

  • A. Mapping opens a path; it does not block.
  • B. This reverses the order.
  • D. It maps one port, not a range.

Question 8Medium

Which Linux kernel features provide container isolation and resource limits?

  1. Namespaces and cgroups
  2. Swap and paging
  3. Cron and systemd timers
  4. Inodes and symlinks

Answer: A. Namespaces and cgroups

Explanation

- Namespaces isolate what a process can see (PIDs, network, mounts);
- cgroups limit CPU, memory and I/O.

Step-by-step solution

  1. Namespaces limit what a process can see: its own PIDs, network, mounts.
  2. cgroups limit what it can use: CPU, memory, I/O.
  3. Together they make a container.

Why the other options are wrong

  • B. Swap and paging are memory management.
  • C. Cron and systemd timers schedule jobs.
  • D. Inodes and symlinks are filesystem structures.

Question 9Hard

In a Dockerfile, why is it common to copy the dependency manifest and install dependencies BEFORE copying the rest of the source code?

  1. To keep the dependency layer cached
  2. So that dependencies are installed only at runtime
  3. Because Docker forbids copying source code first
  4. To make the final image larger and therefore safer

Answer: A. To keep the dependency layer cached

Explanation

Layer caching is invalidated from the first changed step onwards, so placing rarely changing steps first speeds up rebuilds.

Step-by-step solution

  1. Dependencies change rarely; source code changes often.
  2. Copy the manifest and install dependencies first.
  3. Then copy the source; code changes no longer invalidate the cached dependency layer.

Why the other options are wrong

  • B. Dependencies are still installed at build time.
  • C. Docker allows any order.
  • D. Larger images are not safer.

Question 10Hard

Why is running processes as root inside containers discouraged?

  1. Escapes may yield host root
  2. Root processes are unable to use the network
  3. Running as root makes the image much larger
  4. Containers always refuse to start as root

Answer: A. Escapes may yield host root

Explanation

Running as a non-root user follows least privilege and limits the impact of a compromise.

Step-by-step solution

  1. Containers share the host kernel.
  2. If a root process escapes the container, it may gain root on the host.
  3. Running as a non-root user limits the damage.

Why the other options are wrong

  • B. Root processes can use the network.
  • C. The user does not change image size.
  • D. Containers can start as root; that is the default.

Tip: Add a USER line to your Dockerfile.

Practise all 20 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Cloud Computing topics · All topics