0
0
Dockerdevops~5 mins

Connecting containers to multiple networks in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the command to connect an existing Docker container to a new network?
Use docker network connect <network-name> <container-name> to connect a running or stopped container to an additional network.
Click to reveal answer
intermediate
How can a Docker container be connected to multiple networks at creation?
Use the --network flag for the first network and then connect additional networks using docker network connect after the container is created.
Click to reveal answer
beginner
What happens if a container is connected to multiple Docker networks?
The container can communicate with other containers on all connected networks, each network providing a separate IP address inside the container.
Click to reveal answer
beginner
How to list all networks a Docker container is connected to?
Run docker inspect <container-name> and look under the Networks section in the output.
Click to reveal answer
intermediate
Can a container be disconnected from a Docker network? If yes, how?
Yes, use docker network disconnect <network-name> <container-name> to remove a container from a network.
Click to reveal answer
Which command connects a running container named 'webapp' to a network called 'frontend'?
Adocker network connect frontend webapp
Bdocker connect network webapp frontend
Cdocker container connect webapp frontend
Ddocker network attach webapp frontend
What is true about a container connected to multiple Docker networks?
AIt can only communicate on the first network.
BIt merges all networks into one.
CIt loses connectivity on all networks except the last connected.
DIt has multiple IP addresses, one per network.
How do you check which networks a container is connected to?
Adocker inspect &lt;container&gt; and check the Networks section
Bdocker network list --container &lt;container&gt;
Cdocker container networks &lt;container&gt;
Ddocker network show &lt;container&gt;
Can you connect a container to a network after it has started?
AOnly if the container is restarted
BYes, using docker network connect
COnly if the container is stopped
DNo, networks must be set at creation
What command removes a container from a Docker network?
Adocker container disconnect &lt;container&gt; &lt;network&gt;
Bdocker network remove &lt;container&gt;
Cdocker network disconnect &lt;network&gt; &lt;container&gt;
Ddocker network detach &lt;network&gt; &lt;container&gt;
Explain how to connect a Docker container to multiple networks and why this might be useful.
Think about how containers can talk on different networks and how to add networks after creation.
You got /4 concepts.
    Describe the steps to verify and manage network connections of a Docker container.
    Focus on commands to view and change network connections.
    You got /4 concepts.