我遇到了一个让我困惑的问题,我根本不明白为什么会发生这样的事情。
首先,情况是这样的;我有 1 个网络正在运行:macvlan_network(配置为 192.168.10.x 段上的外部 macvlan 网络)
我为 portainer 编写的示例 docker-compose 文件如下所示:
services:
portainer:
image: portainer/portainer-ce:latest
container_name: portainer
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /volume1/docker/portainer:/data
ports:
- 80:8000
- 443:9000
restart: unless-stopped
networks:
macvlan_network:
ipv4_address: 192.168.10.11
mac_address: c0:eb:23:9b:7a:f9
networks:
macvlan_network:
external:
name: macvlan_network
driver: macvlan
当我尝试运行该容器时,我得到:
错误:对于 portainer 无法启动服务 portainer:驱动程序无法在端点 portainer 上编程外部连接(aaa754fb6b68be51d679420fd49b1c5bc9696af517c7d50c77dba75e1c7aeacb):绑定 0.0.0.0:443 失败:端口已分配
但是……这怎么可能呢?0.0.0.0 是本地环回。这是否意味着它完全忽略了 nmacvlan 网络?或者它是否试图在桥接网络(从技术上讲不是 macvlan)上执行此操作,在单个设备上运行,因此会产生干扰?
不再将端口设置为 0.0.0.0,而是将其更改为:
ports:
- "192.168.10.11:80:8000"
- "192.168.10.11:443:9000"
我明白了
错误:对于 6ad1e75e8279_portainer,无法启动服务 portainer:驱动程序无法在端点 portainer 上编程外部连接(04fa9e1d91c229e55c57fb66b0efe89b05c3039d29fc1c048270d383fb9518f8):启动用户空间代理时出错:监听 tcp4 192.168.10.11:443:绑定:无法分配请求的地址
我是否正确地假设这会以某种方式干扰实际主机设备上的端口分配?因为我一直认为 macvlan 网络可以解决这个问题并允许每个单独的虚拟设备上的所有端口。
macvlan_network定义如下:
[
{
"Name": "macvlan_network",
"Id": "0cad5174370c95521fc52dce72128a9a353f2cc124670074bc7effc125e8d416",
"Created": "2023-10-05T23:59:42.889703967+02:00",
"Scope": "local",
"Driver": "macvlan",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "192.168.10.0/24",
"IPRange": "192.168.10.1/24",
"Gateway": "192.168.10.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"6ad1e75e82793c2c14e15120c9aa27f72d4b6e19d556a6ce6c49ff950b003c53": {
"Name": "6ad1e75e8279_portainer",
"EndpointID": "d24966ad3efe46caca837cd3e9467f7efdfb6dc53e428ac1d9e3de921bf4b30c",
"MacAddress": "02:42:c0:a8:0a:0b",
"IPv4Address": "192.168.10.11/24",
"IPv6Address": ""
},
"90e3601b3a96b998456d469ace8390f42830dd6b84402410290678210c934a87": {
"Name": "mosquitto",
"EndpointID": "5fa13668106a9bcb64cc06db899a49734a4b34289f8c1a7b33ef3b3d414a6088",
"MacAddress": "02:42:c0:a8:0a:0a",
"IPv4Address": "192.168.10.10/24",
"IPv6Address": ""
}
}
]