CCNA Lxp Scripting Containers Questions

31 of 106 questions · Page 2/2 · Lxp Scripting Containers topic · Answers revealed

76
Multi-Selecteasy

A Linux administrator wants to create a Docker image from a Dockerfile. Which TWO of the following commands are needed? (Select TWO).

Select 1 answer
A.docker run
B.docker push
C.docker tag
D.docker build
E.docker commit
AnswersD

Builds the image from the Dockerfile.

Why this answer

docker build builds the image; docker tag optionally tags it; docker push uploads to registry; docker run runs a container; docker commit creates image from container.

77
MCQmedium

A system administrator needs to create a Dockerfile for a Python application. The application should be installed in the container, and when the container starts, it should run the command 'python app.py'. Which Dockerfile instruction should be used to specify the default command?

A.ENTRYPOINT python app.py
B.RUN python app.py
C.CMD python app.py
D.STARTUP python app.py
AnswerC

Correct. CMD provides default command for container execution.

Why this answer

CMD specifies the default command to run when the container starts. ENTRYPOINT can also be used but is typically for executables that are not easily overridden.

78
Multi-Selecthard

A DevOps team is designing a containerized application using Docker Compose. They need to ensure that the database container is started before the application container. Which of the following Docker Compose directives can be used to control startup order? (Choose TWO.)

Select 2 answers
A.volumes
B.links
C.environment
D.depends_on
E.healthcheck
AnswersD, E

It specifies dependencies between services.

Why this answer

depends_on ensures that the specified services are started first. healthcheck can be used to wait for a service to be healthy before starting dependent services.

79
MCQeasy

A Linux administrator wants to run a container that stops automatically after the main process exits. Which Docker run flag should be used?

A.--stop-timeout
B.--restart=always
C.--rm
D.-d
AnswerC

Correct. --rm removes the container once it stops.

Why this answer

The --rm flag automatically removes the container when it exits, which is appropriate when the container should stop and be cleaned up after its main process finishes.

80
Multi-Selectmedium

A Linux administrator is writing a Bash script that must handle errors gracefully. Which TWO of the following techniques ensure the script exits on error and provides debugging information? (Select TWO.)

Select 2 answers
A.set -u
B.trap 'echo error' ERR
C.set -x
D.set -e
E.set -o pipefail
AnswersC, D

Prints commands and arguments for debugging.

Why this answer

set -e makes the script exit on any command failure. set -x prints commands as they are executed, aiding debugging. Together they ensure error exit and debugging output.

81
MCQeasy

A DevOps engineer needs to run a Docker container in the background with port mapping from host port 8080 to container port 80, and name the container 'webapp'. Which command accomplishes this?

A.docker start -d -p 8080:80 --name webapp nginx
B.docker create -d -p 8080:80 --name webapp nginx
C.docker run -d -p 8080:80 --name webapp nginx
D.docker compose up -d -p 8080:80 --name webapp nginx
AnswerC

Correct. -d runs detached, -p maps ports, --name assigns a name.

Why this answer

The docker run command with -d (detach), -p (port mapping), and --name options is the correct way to run a container in the background with port mapping and a name.

82
Multi-Selectmedium

A cloud engineer is using Ansible to manage configuration across multiple servers. The engineer needs to store variable data that is specific to each host and sensitive database passwords. Which two Ansible features should be used for these purposes? (Choose two.)

Select 2 answers
A.group_vars
B.ansible_facts
C.roles
D.Ansible Vault
E.host_vars
AnswersD, E

Correct. Vault encrypts sensitive data such as passwords.

Why this answer

host_vars are used for host-specific variables, and Ansible Vault encrypts sensitive data like passwords.

83
MCQeasy

A Bash script contains the following code: if [[ $# -eq 0 ]]; then echo 'No arguments'; fi. What does this code check?

A.Whether the first argument is empty
B.Whether the script was called with no arguments
C.Whether the script has any syntax errors
D.Whether the script is running as root
AnswerB

Correct. $# -eq 0 means zero arguments.

Why this answer

The $# variable holds the number of positional parameters passed to the script. The condition checks if it equals 0, meaning no arguments were provided.

84
MCQmedium

An Ansible playbook is being written to install the Nginx web server on a group of Ubuntu servers. Which module should be used in the playbook to install the package?

A.apt
B.command
C.package
D.yum
AnswerA

apt is the correct module for Ubuntu.

Why this answer

The apt module is used for package management on Debian/Ubuntu systems.

85
MCQmedium

In a bash script, an administrator wants to check if a file exists and is readable. Which of the following test expressions accomplishes this?

A.[ -e file -a -w file ]
B.test -d file -o -r file
C.[[ -f file && -x file ]]
D.[ -f file -a -r file ]
AnswerD

This correctly checks both conditions using the -a operator.

Why this answer

Option D is correct because the test expression `[ -f file -a -r file ]` uses the `-f` flag to check that the file exists and is a regular file, and the `-a` logical AND operator combined with the `-r` flag verifies that the file is readable by the current user. This matches the administrator's requirement exactly.

Exam trap

The Linux+ exam often tests the confusion between file test operators (e.g., `-r` vs `-w` vs `-x`) and the misuse of logical operators (`-a` vs `-o`), leading candidates to select options that check the wrong attribute or combine conditions incorrectly.

How to eliminate wrong answers

Option A is wrong because `[ -e file -a -w file ]` checks if the file exists (`-e`) and is writable (`-w`), not readable. Option B is wrong because `test -d file -o -r file` checks if the file is a directory (`-d`) OR is readable (`-r`), which does not require both conditions and does not verify existence as a regular file. Option C is wrong because `[[ -f file && -x file ]]` checks if the file exists as a regular file (`-f`) AND is executable (`-x`), not readable.

86
MCQeasy

A developer wants to view the logs from a running Docker container named 'myapp'. Which docker command should be used?

A.docker logs myapp
B.docker ps myapp
C.docker exec myapp logs
D.docker inspect myapp
AnswerA

Correct. docker logs displays the logs of the container.

Why this answer

The 'docker logs' command fetches the logs of a container.

87
MCQmedium

A Kubernetes administrator needs to expose a deployment named 'webapp' as a service accessible externally on port 80. Which kubectl command should be used?

A.kubectl port-forward deployment/webapp 80:80
B.kubectl run webapp --port=80
C.kubectl expose deployment webapp --type=NodePort --port=80
D.kubectl create service clusterip webapp --port=80
AnswerC

NodePort exposes the service on a port accessible externally.

Why this answer

kubectl expose deployment webapp --type=NodePort --port=80 creates a service that exposes the deployment externally.

88
MCQhard

An administrator needs to deploy a set of microservices using Docker Compose. The services require configuration values that vary between development and production environments. Which approach allows the administrator to override values without modifying the docker-compose.yml file?

A.Define multiple services in one docker-compose.yml and use profiles.
B.Use environment variables in the Dockerfile and pass them via docker run -e.
C.Use the extends keyword in docker-compose.yml.
D.Use multiple compose files with the -f flag: docker-compose -f docker-compose.yml -f docker-compose.prod.yml up.
AnswerD

Correct. Multiple -f files allow overriding settings from the base file.

Why this answer

Docker Compose supports multiple compose files; using multiple -f options allows overriding values from the base file. Environment-specific files like docker-compose.override.yml are automatically used if present, but using explicit -f options is more flexible for different environments.

89
MCQhard

A containerized application uses a bind mount to persist logs. When the container is removed and recreated, the logs are missing. What is the most likely cause?

A.The container was run with --rm, which deletes the bind mount
B.The host directory was deleted when the container was removed
C.The log files were written to the container's writable layer instead of the mount
D.The bind mount was not specified in the new container run command
AnswerD

Bind mounts are not automatically recreated; they must be specified each time.

Why this answer

Bind mounts depend on the host path; if the bind mount was not re-specified, the new container does not have access to the previous host directory unless explicitly mounted.

90
MCQmedium

A developer is writing a Bash script that needs to parse command-line options with arguments, such as -f filename and -v. Which built-in command should be used to handle these options?

A.getopt
B.getopts
C.case
D.shift
AnswerB

getopts is the built-in command for parsing options in Bash.

Why this answer

getopts is the standard Bash built-in for parsing short options with or without arguments.

91
MCQeasy

Which Dockerfile instruction sets the command to run when the container starts, but allows the user to override it when using docker run?

A.RUN
B.STARTUP
C.ENTRYPOINT
D.CMD
AnswerD

Correct. CMD sets the default command, which can be overridden.

Why this answer

CMD provides defaults for an executing container. If CMD is used, it can be overridden by command-line arguments to docker run. ENTRYPOINT, on the other hand, is not easily overridden without --entrypoint.

92
MCQhard

An administrator needs to create a Docker network of type 'bridge' so that containers can communicate with each other by name. Which command creates a user-defined bridge network named 'my-net'?

A.docker network create my-net
B.docker create network -d bridge my-net
C.docker network create --driver=overlay my-net
D.docker network create -d bridge my-net
AnswerD

Correct. Creates a user-defined bridge network.

Why this answer

User-defined bridge networks provide automatic DNS resolution between containers. The command is 'docker network create' with the -d (driver) flag.

93
MCQmedium

A developer creates a Dockerfile for a web application. Which instruction should be used to define the command that runs when the container starts, allowing the container to accept arguments from the docker run command?

A.START
B.ENTRYPOINT
C.CMD
D.RUN
AnswerC

CMD specifies the default command to run, and can be overridden by docker run arguments.

Why this answer

CMD provides defaults for an executing container, but can be overridden by command-line arguments. ENTRYPOINT is used for main command and CMD for default arguments.

94
MCQeasy

A Docker container needs persistent storage that survives container restarts. Which of the following is the recommended method to achieve this?

A.Use a Docker volume
B.Store data inside the container filesystem
C.Use a bind mount only for configuration files
D.Set the container to always restart
AnswerA

Correct. Volumes are managed by Docker and persist data.

Why this answer

Docker volumes are managed by Docker and are the recommended way to persist data, as they are independent of container lifecycle.

95
MCQmedium

A DevOps engineer is writing a Dockerfile for a Python web application. The base image is python:3.9-slim. The application code is in the current directory, and the container should expose port 8080. Which Dockerfile instructions correctly build the image and run the application using python app.py?

A.FROM python:3.9-slim COPY . /app WORKDIR /app EXPOSE 8080 CMD python app.py
B.FROM python:3.9-slim COPY . /app WORKDIR /app EXPOSE 8080 CMD ['python', 'app.py']
C.FROM python:3.9-slim COPY . /app EXPOSE 8080 ENTRYPOINT python app.py
D.FROM python:3.9-slim WORKDIR /app COPY . . EXPOSE 8080 RUN python app.py
AnswerB

Correct order of instructions; CMD uses JSON array form correctly.

Why this answer

The correct order is: FROM to set base image, COPY to add code, EXPOSE to document port, and CMD to specify the command to run when the container starts.

96
Multi-Selecthard

A Kubernetes administrator is creating a deployment YAML manifest. Which THREE fields are required in a Deployment spec? (Select THREE.)

Select 3 answers
A.replicas
B.spec
C.apiVersion
D.metadata
E.kind
AnswersC, D, E

Correct. Required to specify the API version.

Why this answer

A Deployment requires apiVersion, kind, and metadata. The other fields are part of the spec but not top-level required fields.

97
MCQhard

An administrator wants to run a script on multiple remote servers using Ansible. The script requires a variable that differs per host. Where should the administrator define this variable to follow best practices?

A.In the playbook under vars:
B.In host_vars/<hostname>.yml
C.In the inventory file as a variable
D.In group_vars/all.yml
AnswerB

host_vars allows defining variables specific to a single host.

Why this answer

Host-specific variables should be defined in host_vars files, which are automatically loaded by Ansible when the host is targeted.

98
MCQeasy

Which Kubernetes resource is used to store non-sensitive configuration data as key-value pairs that can be consumed by pods?

A.Deployment
B.Secret
C.Namespace
D.ConfigMap
AnswerD

Correct. ConfigMaps store non-sensitive configuration data.

Why this answer

ConfigMaps are used for non-sensitive configuration data. Secrets are for sensitive data like passwords. Deployments manage replicas of pods.

Namespaces isolate resources.

99
Multi-Selectmedium

An Ansible playbook is being written to manage web servers. Which TWO modules can be used to ensure a package is installed? (Select TWO.)

Select 2 answers
A.copy
B.service
C.apt
D.yum
E.template
AnswersC, D

Correct. Manages packages on Debian/Ubuntu.

Why this answer

The apt module is for Debian-based systems, and yum is for Red Hat-based systems. Both manage packages.

100
MCQeasy

A user wants to execute a command inside a running Docker container named 'db'. Which command should be used?

A.docker attach db
B.docker start -i db
C.docker run -it db bash
D.docker exec -it db bash
AnswerD

Correct. docker exec runs a command in a running container.

Why this answer

docker exec is used to run a command in an existing running container.

101
MCQmedium

A Kubernetes YAML manifest defines a Deployment with 3 replicas. The administrator runs `kubectl get pods` and sees 3 running pods. They then run `kubectl scale deployment mydeployment --replicas=5`. What command would confirm the new number of replicas?

A.kubectl get replicasets
B.kubectl get deployment mydeployment
C.kubectl get pods | wc -l
D.kubectl describe deployment mydeployment
AnswerB

This shows the current state of the deployment, including desired and current replicas.

Why this answer

kubectl get deployment mydeployment shows the current replicas, desired replicas, and status.

102
Multi-Selectmedium

A system administrator is writing an Ansible playbook to manage a web server. Which three of the following are valid Ansible modules for system administration? (Choose THREE.)

Select 3 answers
A.service
B.copy
C.useradd
D.apt
E.chmod
AnswersA, B, D

Controls system services.

Why this answer

apt, service, and copy are standard Ansible modules for package management, service control, and file copying.

103
MCQhard

A Bash script uses getopts to parse command-line options. The options are -a (requires an argument) and -b (flag). Which code correctly implements this and stores the argument for -a in $optarg?

A.while getopts 'a:b' opt; do case $opt in a) arg=$OPTARG ;; b) flag=true ;; esac done
B.while getopts 'ab:' opt; do case $opt in a) arg=$OPTARG ;; b) flag=true ;; esac done
C.while getopts 'a:b' opt; do case $opt in a) arg=$optarg ;; b) flag=true ;; esac done
D.while getopts ':a:b' opt; do case $opt in a) arg=$OPTARG ;; b) flag=true ;; esac done
AnswerA

Correct. The colon after a indicates it requires an argument, and $OPTARG holds the value.

Why this answer

getopts uses the option string 'a:b' where 'a:' indicates -a requires an argument. The argument is stored in the variable $OPTARG (not $optarg).

104
MCQmedium

A bash script needs to test whether a string variable $NAME is non-empty and equals 'admin'. Which of the following conditionals is correct?

A.if [[ $NAME -ne '' && $NAME -eq 'admin' ]]; then
B.if [[ -n $NAME && $NAME == 'admin' ]]; then
C.if [ $NAME != '' ] && [ $NAME == 'admin' ]; then
D.if [ ! -z $NAME -a $NAME = 'admin' ]; then
AnswerB

Correct. -n tests non-empty, == compares strings.

Why this answer

In bash, [[ -n $NAME ]] tests if the string is non-empty, and == compares strings. Using double brackets is safer for string comparison.

105
MCQhard

An administrator is writing a Dockerfile. They need to set a default command that can be overridden when running the container. Which instruction should be used?

A.RUN
B.CMD
C.ENTRYPOINT
D.EXPOSE
AnswerB

CMD provides default command and arguments, which can be overridden by docker run command.

Why this answer

CMD provides defaults that can be overridden by command-line arguments, while ENTRYPOINT cannot be easily overridden without --entrypoint.

106
Multi-Selecthard

A DevOps team uses Podman to run containers rootlessly. Which TWO of the following characteristics apply to rootless Podman compared to Docker? (Select TWO).

Select 2 answers
A.It can only run containers as root
B.It requires a running daemon at all times
C.It uses the same CLI syntax as Docker
D.It supports running containers without root privileges
E.It relies on a central registry for all images
AnswersC, D

Podman is designed to be a drop-in replacement for Docker CLI.

Why this answer

Podman does not require a daemon (no central daemon), and it can run containers without root privileges by default using user namespaces.

← PreviousPage 2 of 2 · 106 questions total

Ready to test yourself?

Try a timed practice session using only Lxp Scripting Containers questions.