0
0
Dockerdevops~20 mins

Connecting containers to multiple networks in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multi-Network Docker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of docker network ls after creating two networks and connecting a container to both?
You create two Docker networks named net1 and net2. Then you run a container mycontainer connected to net1. Finally, you connect mycontainer to net2 using docker network connect. What will docker network ls show regarding these networks?
Docker
docker network create net1
docker network create net2
docker run -dit --name mycontainer --network net1 alpine sh
docker network connect net2 mycontainer
docker network ls
AShows an error because a container cannot be connected to multiple networks.
BLists only net1 network because the container was initially connected to net1.
CLists both net1 and net2 networks with their IDs and drivers, showing both as active networks.
DLists only net2 network because the container was connected last to net2.
Attempts:
2 left
💡 Hint
Think about how Docker networks are listed independently of container connections.
🔀 Workflow
intermediate
2:00remaining
Which sequence correctly connects a running container to two different networks?
You have a running container named webapp. You want to connect it to two networks: frontend and backend. Which sequence of commands will achieve this?
A
docker network create frontend
docker network create backend
docker network connect frontend webapp
docker network connect backend webapp
B
docker network create frontend
RUN docker network connect backend webapp
docker network connect frontend webapp
C
docker network connect frontend webapp
docker network create backend
docker network connect backend webapp
D
docker network create frontend
RUN docker network create backend
RUN docker network connect webapp frontend
RUN docker network connect webapp backend
Attempts:
2 left
💡 Hint
Remember to create networks before connecting containers to them.
Troubleshoot
advanced
2:00remaining
Why does connecting a container to a network fail with "container is already connected to network" error?
You run docker network connect mynet mycontainer but get the error: container is already connected to network mynet. What is the most likely cause?
AThe container is already connected to the network; trying to connect again causes this error.
BThe network <code>mynet</code> does not exist, so Docker cannot connect the container.
CThe container <code>mycontainer</code> is stopped, so it cannot be connected to a network.
DDocker daemon is not running, causing network commands to fail.
Attempts:
2 left
💡 Hint
Check if the container is already connected to the network before connecting again.
🧠 Conceptual
advanced
2:00remaining
What happens to container network connectivity when it is connected to multiple Docker networks?
A container is connected to two Docker networks: netA and netB. How does this affect the container's network interfaces and communication?
AThe container loses network connectivity because Docker does not support multiple networks per container.
BThe container merges both networks into one interface, sharing IP addresses from both networks.
CThe container can only communicate on the first network it was connected to; the second is ignored.
DThe container gets multiple network interfaces, one per network, allowing communication on both networks independently.
Attempts:
2 left
💡 Hint
Think about how physical computers connect to multiple networks with multiple interfaces.
Best Practice
expert
2:00remaining
Which practice is best when connecting containers to multiple networks in production?
In a production environment, you connect containers to multiple Docker networks for isolation and communication. Which practice is best to ensure security and manageability?
AConnect containers to multiple networks randomly to balance traffic automatically.
BUse user-defined bridge networks with clear naming and restrict container connections only to required networks.
CConnect all containers to the default bridge network and add extra networks as needed without restrictions.
DUse host networking mode for all containers to avoid network isolation complexities.
Attempts:
2 left
💡 Hint
Think about network isolation and clarity in production setups.