什么是"Docker子网"?用于? [英] What is the "Docker Subnet" used for?

查看:71
本文介绍了什么是"Docker子网"?用于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

docker-desktop中有一个选项可以更改" Docker子网".而且我看不到在任何地方都使用此默认子网 192.168.65.0/28 .

我尝试在每个Docker内部网络上进行 docker network inspect ,检查了docker-desktop WSL2发行版和Windows主机上的路由或IP,但是我看不到任何地方都使用了默认子网(即使设置了自定义图片也是如此.

这不会更改 docker网络检查网桥或其他任何网络中使用的子网.

我正在努力寻找有关它的用途和/或用途的任何文档.

解决方案

在大多数情况下,这是一个内部实现细节,您无需担心.

您真正需要更改此值的唯一时间是您的主机网络具有相同的地址.在这种情况下,您可以将其更改为任何不冲突的内容.例如,如果您的主机网络恰好是192.168.65.0/24,则可以将Docker网络更改为192.168.66.0/24(或/28),这样就可以正常工作.

内部容器具有单独的IP地址,这是从其分配的默认子网.如果您 docker network create 网络或您正在使用Docker Compose,将分配一个新的子网.这几乎完全是实现细节,您永远不需要知道这些地址:从Docker外部您无法访问这些地址(*),而在Docker内部,它提供了DNS系统,因此您可以将容器名称用作主机名.

更具体地说,如果您

  docker run --rm busybox ifconfig 

您将看到该子网中的地址.

(*)...除了一种非常特殊的情况,即从实际运行容器的本机Linux主机的控制台进行连接;但绝不会来自其他主机,或者如果您使用的是Docker Toolbox或Docker Desktop,则不会.

There is an option in docker-desktop that allow to change the "Docker subnet". And I don't see this default subnet 192.168.65.0/28 being used anywhere.

I tried to docker network inspect on every Docker internal network, checked the docker-desktop WSL2 distro and my Windows host for routes or IPs but I don't see that default subnet being used anywhere (even when setting up a custom one).

This does not change the subnet used in docker network inspect bridge or any other one.

I'm struggling to find any documentation on what it is and/or what it used for.

解决方案

For the most part it is an internal implementation detail that you don't need to worry about.

The only time you actually need to change this value is if your host network has the same address. In that case you can change this to anything that doesn't conflict. If your host network happens to be, for example, 192.168.65.0/24 then you could change the Docker network to 192.168.66.0/24 (or /28) and it'd work fine.

Internally containers have individual IP addresses, and this is the default subnet they get assigned from. If you docker network create a network or you're using Docker Compose, a new subnet will be allocated. This is almost entirely an implementation detail and you never need to know these addresses: from outside Docker you can't reach these addresses (*), and inside Docker it provides a DNS system so you can use container names as host names.

More specifically, if you

docker run --rm busybox ifconfig

you will see an address from this subnet.

(*) ...except in the one very specific case of connecting from the console of the native-Linux host that's actually running the containers; but never from other hosts, or if you're using Docker Toolbox or Docker Desktop.

这篇关于什么是"Docker子网"?用于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆