【问题标题】:Docker compose application has not public ports on digitaloceanDocker compose 应用程序在 digitalocean 上没有公共端口
【发布时间】:2022-12-10 05:34:33
【问题描述】:
我有 docker compose 网络应用程序:
version: '3.3'
services:
app:
image: xxxxxxxxxxxxx
restart: always
network_mode: 'host'
启动后,我可以在服务器上调用wget http://localhost:4004,但是一旦我调用PUBLICIP:4004,它就不起作用了,看起来端口不可访问。防火墙被禁用。我正在使用 ubuntu。
docker compose有什么问题吗?
我试着谷歌和所以
【问题讨论】:
标签:
docker
docker-compose
digital-ocean
【解决方案1】:
如果你只想发布端口添加端口密钥:
version: '3.3'
services:
app:
image: xxxxxxxxxxxxx
ports:
- "4004:4004"
你可以在这里阅读更多:
https://docs.docker.com/compose/networking/
您可能会对将其连接到域并通过 ssl 进行保护感兴趣。我建议你查看nginx-proxy-automation。
https://github.com/evertramos/nginx-proxy-automation
我在我的产品中附加了以下示例,该示例与该库一起使用
version: '3'
services:
gql:
image: registry.digitalocean.com/main/xue-gql
ports:
- ${DOCKER_PORT}:4000
env_file:
- .env
environment:
- VIRTUAL_HOST=${HOST}
- LETSENCRYPT_HOST=${HOST}
- VIRTUAL_PORT=${DOCKER_PORT}
command: node ./src/index.js
redis:
image: 'redis:alpine'
networks:
default:
external:
name: ${NETWORK:-proxy}