QuestionQ93

DevSecOps Pipeline-Operate and Monitor Stage

Peter Dinklage, a senior DevSecOps engineer at SacramentSoft Solution Pvt. Ltd., has deployed applications inside Docker containers. His team leader has asked him to check for the exposure of unnecessary ports.

Which of the following commands should Peter use to check all the containers and their exposed ports?

  • A docker ps --quiet | xargs docker inspect --format : Ports
  • B docker ps --quiet | xargs docker inspect --all --format ‘:Ports=’
  • C docker ps --quiet | xargs docker inspect --all --format : Ports=
  • D docker ps --quiet | xargs docker inspect --format ‘: Ports=’
Explanation

To inspect the exposed ports of all running containers, the correct syntax combines docker ps --quiet (to list only container IDs) with xargs docker inspect --format using a properly quoted Go template referencing the Ports field, such as docker inspect --format '{{.NetworkSettings.Ports}}'. The docker inspect command does not support an --all flag, which eliminates the choices that include it. The format string must also be enclosed in quotes to be passed correctly as a single argument to the --format option, which rules out the unquoted variant. Only the option using docker inspect --format with a quoted template string is syntactically valid Docker CLI usage for retrieving container port information.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!