zoukankan      html  css  js  c++  java
  • docker 容器网络基础

    ========================

    docker缺省自带的网络

    ========================

    host 网络, This enables a container to attach to your host’s network (meaning the configuration inside the container matches the configuration outside the container).

    none 网络, This offers a container-specific network stack that lacks a network interface. This container only has a local loopback interface (i.e., no external network interface).

    bridge 网络, All Docker installations represent the docker0 network with bridge; Docker connects to bridge by default. Run ifconfig on the Linux host to view the bridge network.

    docker network inspect bridge  # find the specific network details
    docker network ls # list all networks

    ========================

    容器缺省使用的网络

    ========================

    1.  在单 host 情况下, docker run 启动容器会加入docker系统自带的 bridge 网络,  即进入网桥模式, 这时docker daemon就会扮演 DHCP 服务器, 为容器分配一个和 docker0 同网段的ip, 并连接到 docker0 . 所以在容器中, 总是可以通过 docker0 的ip 访问到 host 主机. 

    2. 在 swarm 下, 缺省使用 overlay 网络, 适合于多 host 的容器集群. 

    3. 在compose 下, 缺省为 docker-compose.yaml 建立一个 brige 网络, 其中的所有服务都会接入该 bridge 网络, 网络名称由 docker-compose 命令的  -p 或 –project-name 参数指定. 

    ========================

    使用网络

    ========================

    1. 可以使用 docker network 命令增加网络

    2. 可以在 docker-compose.yaml 文件中, 增加 network 并使用网络

    3. 可以使用命令 docker run --net=network_name  , 在容器启动的时候加入到指定的网络

    4. 可以在docker-compose.yaml 文件中, 将 service 加入到已存在的网络中. 

    ========================

    增加网络

    ========================

    增加一个 bridge 网络 

    # docker network create --driver bridge my_first_ever_bridge_network

    增加一个 overlay 网络

      overlay 网络适合多 host 的 容器集群, overlay 网络需要先在 docker daemon 环境中配置好 consul/etcd/zookeeper 存储. 详细操作见: https://foxutech.com/docker-networking/

    ========================

    dns 和 参考

    ========================

    https://foxutech.com/docker-networking-dns/

    https://foxutech.com/docker-networking/

    https://foxutech.com/docker-compose-networking/

  • 相关阅读:
    修改科目的字段状态组-OBC4
    采购收货-对于物料,在工厂、库存地点中不存在物料主数据
    采购收货
    新建工厂
    采购订单收货提示,T169P表不存在
    维护工厂日历
    开始创建物料没有选择会计视图,需要怎么维护
    拓端数据tecdat|R语言分布滞后线性和非线性模型(DLMs和DLNMs)分析时间序列数据
    拓端数据tecdat|R语言分布滞后非线性模型(DLNM)研究发病率,死亡率和空气污染示例
    拓端数据tecdat|R语言中实现广义相加模型GAM和普通最小二乘(OLS)回归
  • 原文地址:https://www.cnblogs.com/harrychinese/p/docker-network2.html
Copyright © 2011-2022 走看看