Scripting, Containers, and Automation for CompTIA Linux+ (XK0-006)

This page covers the Scripting, Containers, and Automation domain of the CompTIA Linux+ (XK0-006) certification. Master Cybersecurity offers 27 practice questions in this domain, drawn from the same content we use across our timed exam simulations. Below are five sample questions with full answer explanations.

Sample Practice Questions

  1. Question 1

    A Linux administrator needs to create and then connect to the app-01-image container. Which of the following commands accomplishes this task?
    1. A. docker run -it app-01-image
    2. B. docker start -td app-01-image
    3. C. docker build -ic app-01-image
    4. D. docker exec -dc app-01-image
    Explanation

    The correct answer is: A. docker run -it app-01-image.

    docker run -it app-01-image creates a new container from the app-01-image image and attaches an interactive TTY to it: -i keeps STDIN open and -t allocates a pseudo-terminal, which together provide an interactive shell into the container as soon as it starts. This is the standard one-shot create-and-connect command. docker start -td app-01-image is wrong on two counts: the argument should be a container name or ID rather than an image, and -d runs in detached mode (the opposite of interactive). docker build -ic app-01-image is malformed — build expects a directory or context and Dockerfile, not the -ic flags shown. docker exec -dc app-01-image is also wrong because exec runs a command in an already-running container (so it does not create one), and the -dc flags it shows are not the correct flags for an interactive session. To both create and immediately interact with a container, docker run -it is the right invocation.

  2. Question 2

    Which of the following Ansible components contains a list of hosts and host groups?
    1. A. Fact
    2. B. Inventory
    3. C. Playbook
    4. D. Collection
    Explanation

    The correct answer is: B. Inventory.

    The Ansible inventory is the file (or dynamic source) that lists the hosts Ansible can manage and groups them logically — for example, [webservers] with three IPs underneath and [dbservers] with two more. Inventories may be static INI/YAML files or generated dynamically from cloud APIs. Facts are key-value pieces of system information Ansible gathers from each managed host (OS, IP, packages, etc.) at the start of a run; they describe state but do not list hosts. Playbooks are YAML files that describe the tasks to apply to hosts and reference inventory groups by name; they consume the inventory rather than contain it. Collections are bundles of related modules, roles, and plugins distributed via Ansible Galaxy and have nothing to do with host enumeration. The inventory is Ansible's authoritative answer to which machines exist.

  3. Question 3

    A Linux user needs to download the latest Debian image from a Docker repository. Which of the following commands makes this task possible?
    1. A. docker image init debian
    2. B. docker image pull Debian
    3. C. docker image import debian
    4. D. docker image save debian
    Explanation

    The correct answer is: B. docker image pull Debian.

    docker image pull retrieves an image from a registry (Docker Hub by default) and stores it in the local image cache, which is exactly what is needed to obtain the latest Debian image. The shorthand docker pull debian:latest works the same way. docker image init is not a valid subcommand — there is no init action under docker image. docker image import takes a tarball produced by docker export or a URL pointing to a tarball and turns it into an image; it does not download from a registry. docker image save is the reverse operation, exporting a local image to a tarball, which is unrelated to downloading. For pulling images by name from a registry, docker image pull (or docker pull) is the command.

  4. Question 4

    In the echo "profile-$num-$name" line of a shell script, the variable $num seems to not be expanding during execution. Which of the following notations ensures the value is expanded?
    1. A. echo "profile-$(num)-$name"
    2. B. echo 'profile-$num-$name'
    3. C. echo "profile-‘Snum‘-$name"
    4. D. echo "profile-${num}-$name"
    Explanation

    The correct answer is: D. echo "profile-${num}-$name".

    Within double-quoted strings, Bash expands $name when followed by a non-name character; when the variable name runs into adjacent characters (like a hyphen) the parser may misread the boundary. The brace form ${num} explicitly delimits the variable name so the shell knows exactly where it ends, ensuring profile-${num}-$name expands cleanly. echo "profile-$(num)-$name" is command substitution: $(...) tries to run num as a command and capture its output, which usually fails or returns nothing. Single quotes around the entire string suppress all variable expansion, so $num would print literally. Backticks around what looks like Snum are also command-substitution syntax (here garbled with smart quotes, which would not parse anyway). The brace form is the canonical way to expand a variable next to other characters without ambiguity.

  5. Question 5

    Which of the following is a characteristic of Python 3?
    1. A. It is closed source.
    2. B. It is extensible through modules.
    3. C. It is fully backwards compatible.
    4. D. It is binary compatible with Java.
    Explanation

    The correct answer is: B. It is extensible through modules..

    Python 3 is highly extensible through modules: any third-party or standard-library module can be loaded with import to add functionality, and the Python Package Index (PyPI) makes thousands of additional modules available via pip. The language itself is open source under the PSF license, not closed source. Python 3 is intentionally not fully backwards compatible with Python 2 — incompatible changes to print, division semantics, string handling, and library names were the entire reason for the major-version bump, and tools like 2to3 exist precisely because the languages diverge. Python 3 is also not binary compatible with Java; CPython compiles to its own bytecode that runs on the Python interpreter, while Java compiles to JVM bytecode. The defining trait of Python's ecosystem is the strength and breadth of its module library.

Other CompTIA Linux+ (XK0-006) domains

Practice all 27 Scripting, Containers, and Automation questions · Browse CompTIA Linux+ (XK0-006)