305-300 practice question 6 of 15

After creating a new Docker network using the following command: docker network create --driver bridge isolated_nw which parameter must be added to docker create in order to attach a container to the network?

Full set: 121 questions
Answer options
A: --eth0=isolated_nw
B: --alias=isolated_nw
C: --ethernet=isolated_nw
D: --network=isolated_nw Correct answer
E: --attach=isolated_nw
Correct Answer:
D. --network=isolated_nw
Explanation

To attach a container to a specific, user-defined network at creation time, the --network flag is used with the docker create or docker run command. This flag takes the name or ID of the target network as its argument. In this scenario, the network is named isolatednw, so the correct parameter is --network=isolatednw. This connects the container's network stack to the specified bridge network, allowing it to communicate with other containers on the same network using their names as hostnames.

Why Incorrect

--eth0=isolatednw: This is not a valid Docker CLI option for specifying a network connection. --alias=isolatednw: This option sets a network-scoped alias for a container but does not attach it to the network; it is used in conjunction with --network. --ethernet=isolatednw: This is not a valid Docker CLI option. --attach=isolatednw: This flag is used to attach the local standard input, output, and error streams to a running container, not for network configuration.

References

1. Docker Inc. Official Documentation, docker run command reference: The documentation explicitly lists the --network option. It states, "Connect a container to a network." The usage examples show how to connect a container to a user-defined bridge network. (See section: "Network settings", --network option).

Source: Docker Docs, docs.docker.com/engine/reference/commandline/run/#network-settings

2. Docker Inc. Official Documentation, Networking with standalone containers: This guide details how to use user-defined bridge networks and confirms the use of docker run --network= ... to connect a container to a specific network upon startup.

Source: Docker Docs, docs.docker.com/network/network-tutorial-standalone/#use-user-defined-bridge-networks

3. Cornell University, CS 5356: "Startup-Scale System Design", Lecture 10: Containers & Docker: The course slides demonstrate container creation and networking. Slide 28 explicitly shows the command docker run --network my-net ... to connect a container to a custom network named my-net.

Source: Cornell University, www.cs.cornell.edu/courses/cs5356/2020sp/slides/10-docker.pdf, Slide 28.

Scroll to Top