【问题标题】: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有什么问题吗?

我试着谷歌和所以

【问题讨论】:

  • 您通常不需要使用 network_mode: host 禁用 Docker 网络...但除此之外,这里没有足够的细节来说明更多。您可以edit 问题中包含minimal reproducible example 吗?这是一个编程问题,还是更多关于部署机制的问题?

标签: 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}

【讨论】:

    猜你喜欢
    • 2016-04-10
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 2019-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多