码迷,mamicode.com
首页 > Web开发 > 详细

Docker-2:network containers

时间:2016-11-14 15:17:02      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:start   work   tin   web   --   docker   end   log   style   

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 bridge
docker network ls
docker run -itd --name=networktest ubuntu #container named networktest from image ubuntu has defaultly connected to bridge
docker network inspect bridge
docker network create -d bridge my-bridge-network #create a new network space "my-bridge-network" with network type "bridge", the other type is "overlay".
docker network ls
docker 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-network 
docker inspect my-bridge-network
docker inspect --format={{json .NetworkSettings.Networks}} db # check the networking of container db
docker inspect --format={{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} db # check the networking of container db
docker 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 web
docker exec -it db bash #run container db with bash cmd #in the container, we use ping ip_of_web, it fails for web is in bridge while db is in my-bridge-network, eventhough both web and db containers are from the SAME image
docker network connect my-bridge-network web #now connect web to my-bridge-network,Docker networking allows you to attach a container to as many networks as you like. 
docker exec -it db bash #run container db with bash cmd, use ping web. succeed cause web and db are in the same network

 

Docker-2:network containers

标签:start   work   tin   web   --   docker   end   log   style   

原文地址:http://www.cnblogs.com/chaseblack/p/6061466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!