Docker run-d-P--name web Training/webapp python app.py#-name means give the To-be-run container a name ' Web '.-p means Connect web to default network space BridgeDocker network Lsdocker run-ITD--name=networktest Ubuntu#container named Networktest from image Ubuntu have defaultly connected to bridgeDocker Network Inspect Bridgedocker network Create-D Bridge my-bridge-network#Create a new network space "my-bridge-network" with network Type "bridge", and the other type is "overlay".Docker Network Lsdocker network inspect my-bridge-Network Docker Run-D--network=my-bridge-network--name db Training/webapp#Run Container "db" and add it to my-bridge-networkDocker Inspect my-bridge-Networkdocker Inspect--format='{{json. Networksettings.networks}}'Db#Check the networking of container dbDocker Inspect--format='{{range. networksettings.networks}}{{. Ipaddress}}{{end}}'Db#Check the networking of container dbDocker run-d-P--name web Training/webapp python app.py#start a container web in net Space "bridge"Docker Inspect--format='{{range. networksettings.networks}}{{. Ipaddress}}{{end}}'Web#Check the networking of container webDockerexec-it DB Bash#run container db with bash cmd #in the container, we use ping ip_of_web, it fails for web are in bridge and DB is in My-bridge-network, eventhough both Web and DB containers is from the same imageDocker Network Connect My-bridge-network Web#Now Connect Web to My-bridge-network,docker networking allows attach a container to as many networks as you lik E.Dockerexec-it DB Bash#run container db with bash cmd, use ping web. Succeed cause web and DB is in the same network
Docker-2:network containers