我是用 Dokploy 部署的。
你这个服务的配置文件还能再优化一下。
按照官方文档的说明,docker-compose.yml 是为了向下兼容,官方推荐使用 compose.yaml
https://docs.docker.com/compose/intro/compose-application-model/使用 compose.override.yaml 来覆盖 env-file ,方便外部不依赖 .env 文件也能直接部署。比如:
https://labs.play-with-docker.com/?stack=https://git.via.moe/dejavu/selfhosted/raw/branch/master/it-tools/docker-compose.yml我之前也是像你这样用 127.0.0.1:8080:80 这样指定内网端口。现在我直接给它设置一个中间网络,再指定其 IP 。外部直接用它这个虚拟 IP 访问:
```bash
docker network create sharenet
docker network inspect sharenet
docker network inspect sharenet | grep Gateway | cut -d'"' -f4
```
```yaml
networks:
sharenet:
external: true
services:
serv:
...
networks:
sharenet:
ipv4_address: 172.19.0.2
```
根据需求,自己定义一个对应网段的 IP 。宿主机可以直接访问 172.19.0.2:80 (假如容器的内部端口 80 )
https://docs.docker.com/reference/compose-file/networks/#external若容器有访问宿主机网络的需求,那就再添加一个
```yaml
extra_hosts:
- "host.docker.internal:host-gateway"
```
https://docs.docker.com/reference/cli/docker/container/run/#add-host