• Docker-2:network containers


    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
  • 相关阅读:
    Nginx出现413 Request Entity Too Large错误解决方法
    Apache设置二级域名和虚拟主机
    LNMP搭建03 -- 编译安装PHP
    LNMP搭建04 -- 配置Nginx支持PHP
    LNMP搭建01 -- 编译安装MySQL 5.6.14 和 LNMP相关的区别
    LNMP搭建02 -- 编译安装Nginx
    vagrant使用小结
    LeetCode Count and Say
    基于ArcGIS Flex API实现动态标绘(1.0)
    HDU 2027 汉字统计
  • 原文地址:https://www.cnblogs.com/chaseblack/p/6061466.html
Copyright © 2020-2023  润新知