5

【笔记】Docker创建网络配置

 1 year ago
source link: https://blog.loli.fj.cn/2023/05/07/Docker%E5%88%9B%E5%BB%BA%E7%BD%91%E7%BB%9C%E9%85%8D%E7%BD%AE/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【笔记】Docker创建网络配置

2023-05-07

Docker创建网络配置学习笔记

查看所有网络配置

docker network ls

删除网络配置

<id>:网络配置编号或名称

docker network rm <id>

host网络配置

  • host网络配置是主机模式,无需创建,是Docker内置的网络配置
  • 在host网络中创建的容器与宿主机共享IP地址,通常用于部署Web应用

none网络配置

  • none网络配置是无网络模式,无需创建,是Docker内置的网络配置
  • 在none网络中创建的容器无网络连接,通常用于单机应用

桥接模式网络配置

  • 桥接模式可以创建多个网段,通常用于隔离网络,通过Docker将多个网段桥接连在一起,
  • 桥接的网段不可以是宿主机的网段

--subnet=:指定网段
doc_bridge:网络配置名称

docker network create --subnet=192.168.0.0/24 doc_bridge

macvlan网络配置

  • Docker容器正常情况下不能和宿主机在相同的网段,可以通过开启了混杂模式(混淆模式)的网卡配置macvlan网络实现容器与宿主机在相同网段

  • 开启网卡的混杂模式(混淆模式)

ip link set lan1 promisc on
  • 创建macvlan网络配置

--subnet=:设置和宿主机相同的网段
--gateway=:设置和宿主机相同的网段的网关
parent:设置已经设置为混杂模式的网卡
doc_macvlan:docker网络名称

docker network create -d macvlan --subnet=192.168.200.0/24 --gateway=192.168.200.1 -o parent=lan1 doc_macvlan

启动容器时指定网络配置

--network=:指定网络模式名
--ip=:指定容器IP地址

docker run <name>

易百教程
Docker官方文档
哔哩哔哩——小黑智能


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK