Document Docker port selection on multiple exposed ports

This commit is contained in:
Mathias Brodala 2024-07-29 10:22:04 +02:00 committed by GitHub
parent 0f4e72d522
commit 3ba53df005
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View file

@ -117,12 +117,14 @@ When using Docker Compose, labels are specified by the directive
Traefik retrieves the private IP and port of containers from the Docker API. Traefik retrieves the private IP and port of containers from the Docker API.
Port detection works as follows: Port detection for private communication works as follows:
- If a container [exposes](https://docs.docker.com/engine/reference/builder/#expose) a single port, - If a container [exposes](https://docs.docker.com/engine/reference/builder/#expose) a single port,
then Traefik uses this port for private communication. then Traefik uses this port.
- If a container [exposes](https://docs.docker.com/engine/reference/builder/#expose) multiple ports, - If a container [exposes](https://docs.docker.com/engine/reference/builder/#expose) multiple ports,
or does not expose any port, then you must manually specify which port Traefik should use for communication then Traefik uses the lowest port. E.g. if `80` and `8080` are exposed, Traefik will use `80`.
- If a container does not expose any port, or the selection from multiple ports does not fit,
then you must manually specify which port Traefik should use for communication
by using the label `traefik.http.services.<service_name>.loadbalancer.server.port` by using the label `traefik.http.services.<service_name>.loadbalancer.server.port`
(Read more on this label in the dedicated section in [routing](../routing/providers/docker.md#port)). (Read more on this label in the dedicated section in [routing](../routing/providers/docker.md#port)).

View file

@ -66,10 +66,11 @@ With Docker, Traefik can leverage labels attached to a container to generate rou
``` ```
!!! important "Traefik Connecting to the Wrong Port: `HTTP/502 Gateway Error`" !!! important "Traefik Connecting to the Wrong Port: `HTTP/502 Gateway Error`"
By default, Traefik uses the first exposed port of a container. By default, Traefik uses the lowest exposed port of a container as detailed in
[Port Detection](../providers/docker.md#port-detection) of the Docker provider.
Setting the label `traefik.http.services.xxx.loadbalancer.server.port` Setting the label `traefik.http.services.xxx.loadbalancer.server.port`
overrides that behavior. overrides this behavior.
??? example "Specifying more than one router and service per container" ??? example "Specifying more than one router and service per container"