You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* generate configs using both docker.sock and DOCKER_HOST data
* parse multiple hosts from DOCKER_HOST
* enable generating swag_url with host friendly name inserted
* maintain backwards compatibility with current functionality
Copy file name to clipboardExpand all lines: README.md
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Auto-proxy - Docker mod for SWAG
2
2
3
-
This mod gives SWAG the ability to auto-detect running containers via labels and automatically enable reverse proxy for them.
3
+
This mod gives SWAG the ability to auto-detect running containers, across multiple hosts, via labels and automatically enable reverse proxy for them.
4
4
5
5
## Requirements:
6
6
- 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`.
7
-
- 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.
7
+
- 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.
8
8
- Containers to be auto-detected and reverse proxied must have a label `swag=enable` at a minimum.
9
9
- 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`).
10
10
@@ -36,3 +36,28 @@ Here's a sample compose yaml snippet for tecnativa/docker-socket-proxy:
36
36
- POST=0
37
37
```
38
38
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.
39
+
40
+
## Multiple Hosts:
41
+
42
+
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.
43
+
44
+
Multiple remote hosts can be used via `DOCKER_HOST` by separating hosts with a comma. Additionally, a friendly host name can be assigned by suffixing the host with `|friendlyName`. If the host is not assigned a friendly name it will have a default generated like `hostN` where N is the position of the host in `DOCKER_HOST`. Example:
If the detected containers for each host do not have the `swag_address` label set then the host IP will be used.
55
+
56
+
If the detected containers for each host do not have the `swag_url` label set then the default can be configured with friendly host name inserted into the url as either a suffix or prefix using the env `HOST_INSERT`. Example:
echo"**** Using preset proxy conf for ${CONTAINER_ID} ****"
54
57
if [ -n"${swag_auth_bypass}" ];then
55
58
echo"**** Swag auth bypass is auto managed via preset confs and cannot be overridden via env vars ****"
56
59
fi
57
60
if [ -n"${swag_address}" ];then
58
-
sed -i "s|set \$upstream_app .*|set \$upstream_app ${swag_address};|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
59
-
echo"**** Overriding address as ${swag_address} for ${CONTAINER} ****"
61
+
sed -i "s|set \$upstream_app .*|set \$upstream_app ${swag_address};|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
62
+
echo"**** Overriding address as ${swag_address} for ${CONTAINER_ID} ****"
60
63
fi
61
64
if [ -n"${swag_port}" ];then
62
-
sed -i "s|set \$upstream_port .*|set \$upstream_port ${swag_port};|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
63
-
echo"**** Overriding port as ${swag_port} for ${CONTAINER} ****"
65
+
sed -i "s|set \$upstream_port .*|set \$upstream_port ${swag_port};|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
66
+
echo"**** Overriding port as ${swag_port} for ${CONTAINER_ID} ****"
64
67
fi
65
68
if [ -n"${swag_proto}" ];then
66
-
sed -i "s|set \$upstream_proto .*|set \$upstream_proto ${swag_proto};|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
67
-
echo"**** Overriding proto as ${swag_proto} for ${CONTAINER} ****"
69
+
sed -i "s|set \$upstream_proto .*|set \$upstream_proto ${swag_proto};|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
70
+
echo"**** Overriding proto as ${swag_proto} for ${CONTAINER_ID} ****"
68
71
fi
69
72
if [ -n"${swag_url}" ];then
70
-
sed -i "s|server_name .*|server_name ${swag_url};|""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
71
-
echo"**** Overriding url as ${swag_url} for ${CONTAINER} ****"
73
+
sed -i "s|server_name .*|server_name ${swag_url};|""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
74
+
echo"**** Overriding url as ${swag_url} for ${CONTAINER_ID} ****"
72
75
fi
73
76
if [ "${swag_auth}"=="authelia" ];then
74
-
sed -i "s|#include /config/nginx/authelia|include /config/nginx/authelia|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
75
-
echo"**** Enabling Authelia for ${CONTAINER} ****"
77
+
sed -i "s|#include /config/nginx/authelia|include /config/nginx/authelia|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
78
+
echo"**** Enabling Authelia for ${CONTAINER_ID} ****"
76
79
elif [ "${swag_auth}"=="authentik" ];then
77
-
sed -i "s|#include /config/nginx/authentik|include /config/nginx/authentik|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
78
-
echo"**** Enabling Authentik for ${CONTAINER} ****"
80
+
sed -i "s|#include /config/nginx/authentik|include /config/nginx/authentik|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
81
+
echo"**** Enabling Authentik for ${CONTAINER_ID} ****"
79
82
elif [ "${swag_auth}"=="http" ];then
80
-
sed -i "s|#auth_basic|auth_basic|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
81
-
echo"**** Enabling basic http auth for ${CONTAINER} ****"
83
+
sed -i "s|#auth_basic|auth_basic|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
84
+
echo"**** Enabling basic http auth for ${CONTAINER_ID} ****"
82
85
elif [ "${swag_auth}"=="ldap" ];then
83
86
# Old (before standard-base)
84
-
sed -i "s|#include /config/nginx/ldap.conf;|include /config/nginx/ldap.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
85
-
sed -i "s|#auth_request /auth;|auth_request /auth;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
86
-
sed -i "s|#error_page 401 =200 /ldaplogin;|error_page 401 =200 /ldaplogin;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
87
+
sed -i "s|#include /config/nginx/ldap.conf;|include /config/nginx/ldap.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
88
+
sed -i "s|#auth_request /auth;|auth_request /auth;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
89
+
sed -i "s|#error_page 401 =200 /ldaplogin;|error_page 401 =200 /ldaplogin;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
87
90
# New (after standard-base)
88
-
sed -i "s|#include /config/nginx/ldap-server.conf;|include /config/nginx/ldap-server.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
89
-
sed -i "s|#include /config/nginx/ldap-location.conf;|include /config/nginx/ldap-location.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
90
-
echo"**** Enabling basic http auth for ${CONTAINER} ****"
91
+
sed -i "s|#include /config/nginx/ldap-server.conf;|include /config/nginx/ldap-server.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
92
+
sed -i "s|#include /config/nginx/ldap-location.conf;|include /config/nginx/ldap-location.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
93
+
echo"**** Enabling basic http auth for ${CONTAINER_ID} ****"
91
94
fi
92
95
else
93
-
echo"**** No preset proxy conf found for ${CONTAINER}, generating from scratch ****"
sed -i "s|<container_name>|${swag_address}|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
118
-
echo"**** Setting upstream address ${swag_address} for ${CONTAINER} ****"
124
+
sed -i "s|<container_name>|${swag_address}|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
125
+
echo"**** Setting upstream address ${swag_address} for ${CONTAINER_ID} ****"
119
126
if [ -z"${swag_port}" ];then
120
127
swag_port=$(docker inspect ${CONTAINER}| jq -r '.[0].NetworkSettings.Ports | keys[0]'| sed 's|/.*||')
121
128
if [ "${swag_port}"=="null" ];then
122
-
echo"**** No exposed ports found for ${CONTAINER}. Setting reverse proxy port to 80. ****"
129
+
echo"**** No exposed ports found for ${CONTAINER_ID}. Setting reverse proxy port to 80. ****"
123
130
swag_port="80"
124
131
fi
125
132
fi
126
-
sed -i "s|set \$upstream_port .*|set \$upstream_port ${swag_port};|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
127
-
echo"**** Setting port ${swag_port} for ${CONTAINER} ****"
133
+
sed -i "s|set \$upstream_port .*|set \$upstream_port ${swag_port};|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
134
+
echo"**** Setting port ${swag_port} for ${CONTAINER_ID} ****"
128
135
if [ -z"${swag_proto}" ];then
129
136
swag_proto="http"
130
137
fi
131
-
sed -i "s|set \$upstream_proto .*|set \$upstream_proto ${swag_proto};|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
132
-
echo"**** Setting proto ${swag_proto} for ${CONTAINER} ****"
138
+
sed -i "s|set \$upstream_proto .*|set \$upstream_proto ${swag_proto};|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
139
+
echo"**** Setting proto ${swag_proto} for ${CONTAINER_ID} ****"
133
140
if [ -z"${swag_url}" ];then
134
-
swag_url="${CONTAINER}.*"
141
+
if [ "$HOST_INSERT"=="suffix" ];then
142
+
swag_url="${CONTAINER}-${DOCKER_HOST_NAME}.*"
143
+
elif [ "$HOST_INSERT"=="prefix" ];then
144
+
swag_url="${DOCKER_HOST_NAME}-${CONTAINER}.*"
145
+
else
146
+
swag_url="${CONTAINER}.*"
147
+
fi
135
148
fi
136
-
sed -i "s|server_name .*|server_name ${swag_url};|""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
137
-
echo"**** Setting url ${swag_url} for ${CONTAINER} ****"
149
+
sed -i "s|server_name .*|server_name ${swag_url};|""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
150
+
echo"**** Setting url ${swag_url} for ${CONTAINER_ID} ****"
138
151
if [ "${swag_auth}"=="authelia" ];then
139
-
sed -i "s|#include /config/nginx/authelia|include /config/nginx/authelia|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
140
-
echo"**** Enabling Authelia for ${CONTAINER} ****"
152
+
sed -i "s|#include /config/nginx/authelia|include /config/nginx/authelia|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
153
+
echo"**** Enabling Authelia for ${CONTAINER_ID} ****"
141
154
elif [ "${swag_auth}"=="authentik" ];then
142
-
sed -i "s|#include /config/nginx/authentik|include /config/nginx/authentik|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
143
-
echo"**** Enabling Authentik for ${CONTAINER} ****"
155
+
sed -i "s|#include /config/nginx/authentik|include /config/nginx/authentik|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
156
+
echo"**** Enabling Authentik for ${CONTAINER_ID} ****"
144
157
elif [ "${swag_auth}"=="http" ];then
145
-
sed -i "s|#auth_basic|auth_basic|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
146
-
echo"**** Enabling basic http auth for ${CONTAINER} ****"
158
+
sed -i "s|#auth_basic|auth_basic|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
159
+
echo"**** Enabling basic http auth for ${CONTAINER_ID} ****"
147
160
elif [ "${swag_auth}"=="ldap" ];then
148
161
# Old (before standard-base)
149
-
sed -i "s|#include /config/nginx/ldap.conf;|include /config/nginx/ldap.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
150
-
sed -i "s|#auth_request /auth;|auth_request /auth;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
151
-
sed -i "s|#error_page 401 =200 /ldaplogin;|error_page 401 =200 /ldaplogin;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
162
+
sed -i "s|#include /config/nginx/ldap.conf;|include /config/nginx/ldap.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
163
+
sed -i "s|#auth_request /auth;|auth_request /auth;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
164
+
sed -i "s|#error_page 401 =200 /ldaplogin;|error_page 401 =200 /ldaplogin;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
152
165
# New (after standard-base)
153
-
sed -i "s|#include /config/nginx/ldap-server.conf;|include /config/nginx/ldap-server.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
154
-
sed -i "s|#include /config/nginx/ldap-location.conf;|include /config/nginx/ldap-location.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
155
-
echo"**** Enabling basic http auth for ${CONTAINER} ****"
166
+
sed -i "s|#include /config/nginx/ldap-server.conf;|include /config/nginx/ldap-server.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
167
+
sed -i "s|#include /config/nginx/ldap-location.conf;|include /config/nginx/ldap-location.conf;|g""/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
168
+
echo"**** Enabling basic http auth for ${CONTAINER_ID} ****"
0 commit comments