Which command would display the hostname of a container by reading /etc/hostname inside the container?

Prepare for the Red Hat OpenShift Developer II DO288 Exam with our quizzes. Study with flashcards and multiple choice questions, each with hints and explanations. Get ready for your certification!

Multiple Choice

Which command would display the hostname of a container by reading /etc/hostname inside the container?

Explanation:
To see the hostname stored inside a running container, you read the file that holds it from within the container. Podman exec lets you run a command inside a running container, so executing cat /etc/hostname prints exactly what’s written in that file. This matches the requirement of reading the hostname from inside the container’s filesystem. Using the hostname command would query the system's kernel hostname, which may be the same value but doesn’t specifically read the contents of /etc/hostname. Podman inspect returns container metadata in JSON, not the file contents. Running a new container with run would not fetch the hostname from the existing container’s filesystem.

To see the hostname stored inside a running container, you read the file that holds it from within the container. Podman exec lets you run a command inside a running container, so executing cat /etc/hostname prints exactly what’s written in that file. This matches the requirement of reading the hostname from inside the container’s filesystem.

Using the hostname command would query the system's kernel hostname, which may be the same value but doesn’t specifically read the contents of /etc/hostname. Podman inspect returns container metadata in JSON, not the file contents. Running a new container with run would not fetch the hostname from the existing container’s filesystem.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy