Network Flashcards
List networks
docker network ls
Get detailed info of a network
docker network inspect network_name
Create/Delete a network
docker network create network_name
docker network rm network_name
Delete all unused networks
docker network prune
Add/remove a container to existing network
docker network connect network-name container
docker network disconnect network-name container
Create network specifying a subnet and gateway of this subnet
docker network create –subnet 10.0.1.0/24 –gateway 10.0.1.1 my_net
docker network create –subnet 10.2.0.0/16 –gateway 10.2.0.1 –ip-range=10.2.5.0/24 –driver=bridge –label=host4net br001
docker network inspect br001
Create container and network, assign container to a network
- docker container run –name nginx-cont -d nginx
docker network create my_net
docker network connect nginx-cont my_net - docker network create –subnet 10.2.0.0/16 –gateway 10.0.0.1 –ip-range=10.2.5.0 –driver=bridge –label=host1net br001
2.1.
docker container run –name centos-cont -dit –network br001 centos /bin/bash
yum -y update
yum install -y net-tools
ip addr=> ip will be from ip-range, for example 10.2.5.1
2.2.
docker container run –name nginx-cont –ip 10.2.5.100 -d –network br001 nginx
docker container inspect nginx-cont | grep -i ipaddr