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
  • 相关阅读:
    lintcode:Binary Search 二分查找
    lintcode:1-10题
    leetcode 5 :Longest Palindromic Substring 找出最长回文子串
    leetcode 4 : Median of Two Sorted Arrays 找出两个数组的中位数
    Project Euler 78:Coin partitions
    Project Euler 77:Prime summations
    Project Euler 76:Counting summations
    筛选法求素数
    Codeforces D546:Soldier and Number Game
    Project Euler 75:Singular integer right triangles
  • 原文地址:https://www.cnblogs.com/chaseblack/p/6061466.html
Copyright © 2011-2022 走看看