【发布时间】:2022-01-09 06:45:29
【问题描述】:
我有一个类似于以下内容的 docker-compose 文件:
version: "3.1"
services:
app:
container_name: Apache_web_server
image: httpd:2.4
ports:
- 40:80
restart: unless-stopped
volumes:
- ./web-root:/usr/local/apache2/htdocs
按照目前的配置,任何 IP 都可以访问 apache 网络服务器的 40 端口。我可以将端口部分更改为:
ports:
- "127.0.0.1:40:80"
而且它只允许来自 localhost 的 40 端口的流量进入容器,但是如果我将端口部分更改为:
ports:
- "192.168.1.24:40:80"
然后尝试打开容器,我得到了这个可爱的错误:
ERROR: for Apache_web_server Cannot start service app: driver failed programming external connectivity on endpoint Apache_web_server ([ID]): Error starting userland proxy: listen tcp4 192.168.1.24:40: bind: cannot assign requested address
ERROR: for app Cannot start service app: driver failed programming external connectivity on endpoint Apache_web_server ([ID]): Error starting userland proxy: listen tcp4 192.168.1.24:40: bind: cannot assign requested address
有人知道这是怎么回事吗?我想(在此示例中)将对 apache Web 服务器的访问限制为仅来自 IP 192.168.1.24 的请求。
【问题讨论】:
-
能够使用@gohm'c提供的this帖子中的代码
标签: docker docker-compose portforwarding