What is the purpose of using the -p option in 'docker run -d --rm -p 12345:80 nginx'?

Study for the Kubernetes Cloud Native Associate (KCNA) Certification. Prepare with flashcards and multiple choice questions. Ensure success with detailed explanations. Ready for your exam!

Multiple Choice

What is the purpose of using the -p option in 'docker run -d --rm -p 12345:80 nginx'?

Explanation:
The -p option binds a port on the host to a port inside the container, making the container’s service reachable from outside the container. In this example, -p 12345:80 maps host port 12345 to container port 80 (where nginx serves HTTP). This means you can reach the nginx server at http://host-ip:12345. Without this port publishing, the container’s port 80 would be isolated from the outside world. The option does not perform port scanning, and it does not limit exposure to other containers—it explicitly exposes the specified host port. If a random host port were chosen, you’d see a different host port mapping, which isn’t the case here since 12345 is explicitly specified.

The -p option binds a port on the host to a port inside the container, making the container’s service reachable from outside the container. In this example, -p 12345:80 maps host port 12345 to container port 80 (where nginx serves HTTP). This means you can reach the nginx server at http://host-ip:12345. Without this port publishing, the container’s port 80 would be isolated from the outside world. The option does not perform port scanning, and it does not limit exposure to other containers—it explicitly exposes the specified host port. If a random host port were chosen, you’d see a different host port mapping, which isn’t the case here since 12345 is explicitly specified.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy