zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    第13讲- Android之消息提示Notification
    第12讲- Android之消息提示Toast
    第11讲- Android中进程及其优先级
    第10讲- UI线程阻塞及其优化
    第09讲 常见事件响应2
    听李玫瑾未成年人(0-18岁)心理讲座笔记
    管理经典:善待20%的骨干人才
    再学《多管事,不如抓重点》
    解决难题的最好方法是什么
    孩子14岁前,请一定要告诉他们这7句话!
  • 原文地址:https://www.cnblogs.com/chaseblack/p/6061466.html
Copyright © 2011-2022 走看看