【问题标题】:Multiple Dockerized angular apps on a single host单个主机上的多个 Dockerized Angular 应用程序
【发布时间】:2019-07-03 14:34:51
【问题描述】:

我正在尝试在单个主机上托管 2 个指向不同环境的 Web 控制台的相同图像的容器,并使用 Traefik 容器路由到它们。问题是,第二个容器不可访问。我不断收到错误的网关。

使用第二个容器的端口导航到 IP 失败,但端口映射配置似乎正常。第二个容器中没有日志。

码头工人撰写

  console:
    container_name: console
    image: REDACTED
    environment:
      API_URL: "REDACTED-PRD"
    ports:
      - 4200:4200
    labels:
      - traefik.port=4200
      - traefik.frontend.rule=Host:dev.REDACTED.com
  console-prd:
    container_name: console-prd
    image: REDACTED
    environment:
      API_URL: "REDACTED-DEV"
    ports:
      - 4300:4200
    labels:
      - traefik.port=4300
      - traefik.frontend.rule=Host:app.REDACTED.com
  traefik:
    container_name: traefik
    image: traefik:1.7.10-alpine
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.toml:/etc/traefik/traefik.toml:Z```

ipaddr:4300 gets bad gateway. Traefik logs:

```time="2019-07-03T14:14:21Z" level=debug msg="Upstream ResponseWriter of type *pipelining.writerWithoutCloseNotify does not implement http.CloseNotifier. Returning dummy channel."
time="2019-07-03T14:14:21Z" level=debug msg="'502 Bad Gateway' caused by: dial tcp 192.168.16.3:4300: connect: connection refused"
time="2019-07-03T14:14:21Z" level=debug msg="vulcand/oxy/forward/http: Round trip: http://192.168.16.3:4300, code: 502, Length: 11, duration: 381.832µs tls:version: 303, tls:resume:true, tls:csuite:c02f, tls:server:app.REDACTED.com"
time="2019-07-03T14:14:21Z" level=debug msg="vulcand/oxy/forward/http: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"http\",\"Opaque\":\"\",\"User\":null,\"Host\":\"192.168.16.3:4300\",\"Path\":\"\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"en-US,en;q=0.9\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"app.REDACTED.com\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"148.78.240.30:50437\",\"RequestURI\":\"/\",\"TLS\":null}"
time="2019-07-03T14:14:21Z" level=debug msg="vulcand/oxy/forward: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"http\",\"Opaque\":\"\",\"User\":null,\"Host\":\"192.168.16.3:4300\",\"Path\":\"\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"en-US,en;q=0.9\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"app.REDACTED.com\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"148.78.240.30:50437\",\"RequestURI\":\"/\",\"TLS\":null}"
time="2019-07-03T14:14:21Z" level=debug msg="vulcand/oxy/roundrobin/rr: completed ServeHttp on request" Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/2.0\",\"ProtoMajor\":2,\"ProtoMinor\":0,\"Header\":{\"Accept\":[\"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\"],\"Accept-Encoding\":[\"gzip, deflate, br\"],\"Accept-Language\":[\"en-US,en;q=0.9\"],\"Upgrade-Insecure-Requests\":[\"1\"],\"User-Agent\":[\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"app.REDACTED.com\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"148.78.240.30:50437\",\"RequestURI\":\"/\",\"TLS\":null}"```

【问题讨论】:

    标签: angular docker traefik


    【解决方案1】:

    标签中的 traefik 端口也应为 4200。 Traefik 没有使用发布的端口

    【讨论】:

    • 啊,以为会标记到主机端口,而不是容器的暴露端口。谢谢!
    • 如果您也将 traefik 作为容器启动,它无法连接到主机端口。您还可以删除文件中已发布的端口。这仍然应该有效。
    猜你喜欢
    • 2019-07-27
    • 2017-09-18
    • 2019-05-04
    • 2011-09-24
    • 2019-12-13
    • 1970-01-01
    • 2018-09-04
    • 2012-04-29
    • 2021-11-18
    相关资源
    最近更新 更多