Core commands:
- docker network create
- docker network connect
- docker network ls
- docker network rm
- docker network disconnect
- docker network inspect
Docker Engine automatically creates a default Bridge network by default
Creating a Bridge network is simple as follows:
Bridge network created by default when no network driver is specified
docker network create simple-network
View internal network information
docker network inspect simple-network
Check the network status of the three containers
- docker network inspect container1
- docker network inspect container2
- docker network inspect container3
Disconnect and remove the network
The container is disconnected from the Mynet network (it will no longer be able to communicate with container3 on the network)
docker network disconnect mynet container2
The test with container Container3 failed
Docker attach container2 ping contianer3 When the container is connected to the network with the removed container name, the error “Container is already connected to the network” will occur. In this case, the new container needs to be forcibly removed from the Docker RM -f, run again and connect to the network. Removing a network Requires all containers on the network to close or disconnect from the network before you can run the remove command:
Disconnect the last container connected to the MyNet network
docker network disconnet mynet container3
Remove the network
docker network rm mynet