By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Container communication allows containers to connect and exchange data with each other and the host system. docker network create
docker info
docker network create my-network
docker network ls
docker run -it --name my-container --net my-network ubuntu
docker container prune
docker network inspect my-network
docker run -it --name my-container2 --net my-network ubuntu
Purpose: Create a new network and connect a container to it.Command: docker network create my-network && docker run -it --name my-container --net my-network ubuntu Flags: --net specifies the network to join, && runs the second command only if the first succeeds.
docker network create my-network && docker run -it --name my-container --net my-network ubuntu
--net
&&
Purpose: Connect multiple containers to the same network.Command: docker run -it --name my-container1 --net my-network ubuntu && docker run -it --name my-container2 --net my-network ubuntu Flags: --net specifies the network to join, && runs the second command only if the first succeeds.
docker run -it --name my-container1 --net my-network ubuntu && docker run -it --name my-container2 --net my-network ubuntu
Purpose: Create a new network with a custom driver.Command: docker network create --driver bridge my-network Flags: --driver specifies the network driver to use.
docker network create --driver bridge my-network
--driver
Error message: Error response from daemon: network my-network not found Why it happens: The network was deleted or never created.Fix: docker network create my-network
Error response from daemon: network my-network not found
Error message: Error response from daemon: Container my-container is not connected to any network Why it happens: The container was not joined to a network.Fix: docker run -it --name my-container --net my-network ubuntu
Error response from daemon: Container my-container is not connected to any network
Error message: Error response from daemon: network my-network already exists Why it happens: The network was already created.Fix: docker network rm my-network && docker network create my-network
Error response from daemon: network my-network already exists
docker network rm my-network && docker network create my-network
Situation: You want to verify if a container is connected to a network.Command: docker network inspect my-network Correct response: The container's IP address is listed under the "Containers" section.
Situation: You want to verify if a network exists.Command: docker network ls Correct response: The network's name is listed in the output.
Situation: You want to verify if a container is running.Command: docker ps Correct response: The container's name and ID are listed in the output.
docker ps
docker network prune
docker network inspect
docker network create
docker network rm
docker network connect
docker network disconnect
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.