log*_*ins 5 proxy docker docker-compose windows-subsystem-for-linux caddy
我有一个在 Docker 中运行的 Caddy 服务器与 Node.JS 服务器通信。此设置目前适用于 MacOS,但不适用于 WSL2。我认为这个问题与我们http://host.docker.internal:3000在 Caddyfile 中用作代理地址有关,但我不知道如何编写它,因此它适用于 WSL2 和 MacOS。
docker-compose.yml:
version: '3.7'
services:
caddy:
image: 'abiosoft/caddy:latest'
volumes:
- ./certs:/root/certs # to sync mkcert certificates to Caddy
- ./Caddyfile:/etc/Caddyfile # to mount custom Caddyfile
ports:
- '443:2015'
db:
container_name: service_local_db
image: mysql:8.0
environment:
MYSQL_DATABASE: 'service_local'
MYSQL_ROOT_PASSWORD: '******'
ports:
- '3306:3306'
expose:
- '3306'
volumes:
- database_volume:/var/lib/mysql
volumes:
database_volume:
Run Code Online (Sandbox Code Playgroud)
球童档案
servicename.url{
log stdout
tls /root/certs/servicename.local.pem /root/certs/servicename.local-key.pem
proxy / http://host.docker.internal:3000 {
websocket
transparent
header_upstream X-Marotagem true
header_upstream Host "servicename.local"
}
}
Run Code Online (Sandbox Code Playgroud)
我试过了:
host.docker.internal为host-gateway。即使这确实有效,反过来也不允许它在 MacOS 上工作。'host.docker.internal:host-gateway'作为extra_hosts:下services的泊坞窗,compose.yml。它不起作用,但如果它起作用,我不确定它会如何影响 MacOS。任何帮助,将不胜感激。
AFAIKhost.docker.internal尚未在 Linux 版 Docker 中实现。但由于您使用的是bridge网络(默认网络),因此您可以为主机创建一个静态 IP 地址之类的内容。之后就不需要使用了host.docker.internal,不过如果您愿意,您可以将其添加到带有extra_hosts.
version: "2"
networks:
default:
ipam:
driver: default
config:
# (mandatory) IP-address range for the containers
- subnet: "10.50.0.0/24"
# (optional) IP-address of the host
# if not specified it will be the first IP-address of the subnet (10.50.0.1 in this case)
gateway: 10.50.0.20
# 'gateway' is only available in docker-compose version 2 at the moment
Run Code Online (Sandbox Code Playgroud)
在此示例中,gateway将是该网络中容器的主机 IP 地址。您可以使用该值来创建工作extra_hosts记录:
extra_hosts:
- "host.docker.internal:10.50.0.20"
Run Code Online (Sandbox Code Playgroud)
不幸的是,目前gateway仅在版本撰写文件规范中支持选项,您只能指定. 如果未明确指定,它将是该范围的第一个 IP 地址(对于上面的示例)。23subnetgateway10.50.0.1
配置不需要更改,除非您偶然发现 IP 范围重叠。换句话说,如果您将运行此程序的计算机没有子网(docker 或其他),与您选择的范围重叠,则不会有问题。否则,您可以选择另一个子网并在 中写入不同的地址extra_hosts。
另请注意,一旦创建网络,就不允许更改 IPAM 配置。在创建新网络之前,您需要删除旧网络。使用docker-compose down或docker network rm <network_name>.
| 归档时间: |
|
| 查看次数: |
622 次 |
| 最近记录: |