Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple docker hosts #916

Open
wants to merge 6 commits into
base: swag-auto-proxy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Auto-proxy - Docker mod for SWAG

This mod gives SWAG the ability to auto-detect running containers via labels and automatically enable reverse proxy for them.
This mod gives SWAG the ability to auto-detect running containers, across multiple hosts, via labels and automatically enable reverse proxy for them.

## Requirements:
- This mod needs the [universal-docker mod](https://github.com/linuxserver/docker-mods/tree/universal-docker) installed and set up with either mapping `docker.sock` or setting the environment variable `DOCKER_HOST=remoteaddress`.
- Other containers to be auto-detected and reverse proxied should be in the same [user defined bridge network](https://docs.linuxserver.io/general/swag#docker-networking) as SWAG.
- Other containers detected via `docker.sock` to be auto-detected and reverse proxied should be in the same [user defined bridge network](https://docs.linuxserver.io/general/swag#docker-networking) as SWAG.
- Containers to be auto-detected and reverse proxied must have a label `swag=enable` at a minimum.
- To benefit from curated preset proxy confs we provide, the container name must match the container names that are suggested in our readme examples (ie. `radarr` and not `Radarr-4K`).

Expand Down Expand Up @@ -36,3 +36,63 @@ Here's a sample compose yaml snippet for tecnativa/docker-socket-proxy:
- POST=0
```
Then the env var in SWAG can be set as `DOCKER_HOST=dockerproxy`. This will allow docker cli in SWAG to be able to retrieve info on other containers, but it won't be allowed to spin up new containers.

## Multiple Hosts:

If both `DOCKER_HOST` and `docker.sock` volumes are provided this mod will detect containers using both connections. As noted in the [requirements](#requirements), containers detected via `docker.sock` must be in the same user defined network or have `swag_address` label set.

Multiple remote hosts can be used via `DOCKER_HOST` by separating hosts with a comma. Additional per-host settings can be assigned by separating with a pipe `|`. The syntax for per-host configuration:

```
host:port|friendly_name|default_tld
```


```
DOCKER_HOST=192.168.0.100:2375|serverA,192.168.0.110:2375|serverB|local.test,192.168.0.130:2375
```

* Host: `192.168.0.100:2375` -- Friendly Name: `serverA` -- TLD: `*`
* Host: `192.168.0.110:2375` -- Friendly Name: `serverB` -- TLD: `local.test`
* Host: `192.168.0.130:2375` -- Friendly Name: `host3` -- TLD: `*`

### Upstream IP and Port

When using a remote docker host from `DOCKER_HOST` auto-proxy assumes the detected containers are not on the same network as SWAG:

* If the detected containers do not have the `swag_address` label set then the Host IP will be used.
* If the detected containers do not have the `swag_port` label set then auto-proxy looks for exposed **container ports** and uses the corresponding **host port** as the upstream port. Container ports are checked in this order:
* 80
* 8080
* The first mapped port, if any

### Subdomains and TLD

If a detected container does not have the `swag_url` label set then the subdomain and TLD can be programmatically generated.

The default TLD used in nginx [`server_name` directive](https://nginx.org/en/docs/http/server_names.html) can be set using `AUTO_PROXY_HOST_TLD`. This can also be set per-host using the syntax described in [`DOCKER_HOST` for `default_tld`.](#multiple-hosts)

The subdomain used for a container can optionally be modified to include the Host's `friendly_name` described in the `DOCKER_HOST` syntax by setting `AUTO_PROXY_HOST_INSERT` to either `prefix` or `suffix`

Examples using a container named `overseer`:

* Using only AUTO_PROXY_HOST_INSERT to modify subdomain
* `DOCKER_HOST=192.168.0.100:2375|serverA`
* `AUTO_PROXY_HOST_TLD` (not set, defaults to `*`)
* `AUTO_PROXY_HOST_INSERT`
* (unset) => nginx `server_name overseer.*`
* `prefix` => nginx `server_name serverA-overseer.*`
* `suffix` => nginx `server_name overseer-serverA.*`
* Using AUTO_PROXY_HOST_INSERT prefix and AUTO_PROXY_HOST_TLD
* `DOCKER_HOST=192.168.0.100:2375|serverA`
* `AUTO_PROXY_HOST_TLD=test.home`
* `AUTO_PROXY_HOST_INSERT=prefix`
* `server_name serverA-overseer.test.home`
* Using AUTO_PROXY_HOST_INSERT prefix and default_tld
* `DOCKER_HOST=192.168.0.100:2375|serverA|myserver.home`
* `AUTO_PROXY_HOST_INSERT=prefix`
* `server_name serverA-overseer.myserver.home`
* Using AUTO_PROXY_HOST_TLD only
* `DOCKER_HOST=192.168.0.100:2375`
* `AUTO_PROXY_HOST_TLD=myserver.home`
* `server_name overseer.myserver.home`
Loading