Warm tip: This article is reproduced from stackoverflow.com, please click
angular docker traefik

Multiple Dockerized angular apps on a single host

发布于 2020-03-27 10:24:16

I'm attempting to host 2 containers of the same image of a web console pointed to different environments on a single host and route to them with a Traefik container. The problem is, the second container is not accessible. I keep getting Bad Gateway.

Navigating to the IP with the port of the second container fails, but the port mapping configuration appears fine. There are no logs in the second container.

docker-compose

  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}"```
Questioner
Nick K
Viewed
160
Manuel Polacek 2019-07-03 22:40

The traefik port should be 4200 in the labels as well. Traefik didn't use the published port