Add example for changing the port used by traefik to connect to a service
This commit is contained in:
parent
8f000423ed
commit
f790b9aa54
3 changed files with 139 additions and 115 deletions
|
@ -37,6 +37,27 @@ Attach labels to your containers and let Traefik do the rest!
|
||||||
- traefik.http.routers.my-container.rule=Host(`mydomain.com`)
|
- traefik.http.routers.my-container.rule=Host(`mydomain.com`)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
??? example "Specify a Custom Port for the Container"
|
||||||
|
|
||||||
|
Forward requests for `http://mydomain.com` to `http://<private IP of container>:12345`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
my-container:
|
||||||
|
# ...
|
||||||
|
labels:
|
||||||
|
- traefik.http.routers.my-container.rule=Host(`mydomain.com`)
|
||||||
|
# Tell Traefik to use the port 12345 to connect to `my-container`
|
||||||
|
- traefik.http.services.my-service.loadbalancer.server.port=12345
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! important "Traefik Connecting to the Wrong Port: `HTTP/502 Gateway Error`"
|
||||||
|
By default, Traefik uses the first exposed port of a container.
|
||||||
|
|
||||||
|
Setting the label `raefik.http.services.xxx.loadbalancer.server.port`
|
||||||
|
overrides that behavior.
|
||||||
|
|
||||||
??? example "Configuring Docker Swarm & Deploying / Exposing Services"
|
??? example "Configuring Docker Swarm & Deploying / Exposing Services"
|
||||||
|
|
||||||
Enabling the docker provider (Swarm Mode)
|
Enabling the docker provider (Swarm Mode)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
"extends": "../../../.markdownlint.json",
|
"extends": "../../../.markdownlint.json",
|
||||||
"MD024": false
|
"MD024": false,
|
||||||
|
"MD046": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ Configuring How to Reach the Services
|
||||||
|
|
||||||
The `Services` are responsible for configuring how to reach the actual services that will eventually handle the incoming requests.
|
The `Services` are responsible for configuring how to reach the actual services that will eventually handle the incoming requests.
|
||||||
|
|
||||||
## Configuration Example
|
## Configuration Examples
|
||||||
|
|
||||||
??? example "Declaring an HTTP Service with Two Servers -- Using the [File Provider](../../providers/file.md)"
|
??? example "Declaring an HTTP Service with Two Servers -- Using the [File Provider](../../providers/file.md)"
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ The `Services` are responsible for configuring how to reach the actual services
|
||||||
[http.services.my-service.loadBalancer]
|
[http.services.my-service.loadBalancer]
|
||||||
|
|
||||||
[[http.services.my-service.loadBalancer.servers]]
|
[[http.services.my-service.loadBalancer.servers]]
|
||||||
url = "http://private-ip-server-1/"
|
url = "http://<private-ip-server-1>:<private-port-server-1>/"
|
||||||
[[http.services.my-service.loadBalancer.servers]]
|
[[http.services.my-service.loadBalancer.servers]]
|
||||||
url = "http://private-ip-server-2/"
|
url = "http://<private-ip-server-2>:<private-port-server-2>/"
|
||||||
```
|
```
|
||||||
|
|
||||||
```yaml tab="YAML"
|
```yaml tab="YAML"
|
||||||
|
@ -29,8 +29,8 @@ The `Services` are responsible for configuring how to reach the actual services
|
||||||
my-service:
|
my-service:
|
||||||
loadBalancer:
|
loadBalancer:
|
||||||
servers:
|
servers:
|
||||||
- url: "http://private-ip-server-1/"
|
- url: "http://<private-ip-server-1>:<private-port-server-1>/"
|
||||||
- url: "http://private-ip-server-2/"
|
- url: "http://<private-ip-server-2>:<private-port-server-2>/"
|
||||||
```
|
```
|
||||||
|
|
||||||
??? example "Declaring a TCP Service with Two Servers -- Using the [File Provider](../../providers/file.md)"
|
??? example "Declaring a TCP Service with Two Servers -- Using the [File Provider](../../providers/file.md)"
|
||||||
|
@ -40,9 +40,9 @@ The `Services` are responsible for configuring how to reach the actual services
|
||||||
[tcp.services]
|
[tcp.services]
|
||||||
[tcp.services.my-service.loadBalancer]
|
[tcp.services.my-service.loadBalancer]
|
||||||
[[tcp.services.my-service.loadBalancer.servers]]
|
[[tcp.services.my-service.loadBalancer.servers]]
|
||||||
address = "xx.xx.xx.xx:xx"
|
address = "<private-ip-server-1>:<private-port-server-1>"
|
||||||
[[tcp.services.my-service.loadBalancer.servers]]
|
[[tcp.services.my-service.loadBalancer.servers]]
|
||||||
address = "xx.xx.xx.xx:xx"
|
address = "<private-ip-server-2>:<private-port-server-2>"
|
||||||
```
|
```
|
||||||
|
|
||||||
```yaml tab="YAML"
|
```yaml tab="YAML"
|
||||||
|
@ -51,8 +51,8 @@ The `Services` are responsible for configuring how to reach the actual services
|
||||||
my-service:
|
my-service:
|
||||||
loadBalancer:
|
loadBalancer:
|
||||||
servers:
|
servers:
|
||||||
- address: "xx.xx.xx.xx:xx"
|
- address: "<private-ip-server-1>:<private-port-server-1>"
|
||||||
- address: "xx.xx.xx.xx:xx"
|
- address: "<private-ip-server-2>:<private-port-server-2>"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuring HTTP Services
|
## Configuring HTTP Services
|
||||||
|
@ -61,6 +61,8 @@ The `Services` are responsible for configuring how to reach the actual services
|
||||||
|
|
||||||
The load balancers are able to load balance the requests between multiple instances of your programs.
|
The load balancers are able to load balance the requests between multiple instances of your programs.
|
||||||
|
|
||||||
|
Each service has a load-balancer, even if there is only one server to forward traffic to.
|
||||||
|
|
||||||
??? example "Declaring a Service with Two Servers (with Load Balancing) -- Using the [File Provider](../../providers/file.md)"
|
??? example "Declaring a Service with Two Servers (with Load Balancing) -- Using the [File Provider](../../providers/file.md)"
|
||||||
|
|
||||||
```toml tab="TOML"
|
```toml tab="TOML"
|
||||||
|
|
Loading…
Reference in a new issue