Creating index.html with a list of URLs to published containers

This commit is contained in:
Anielkis Herrera 2018-12-27 16:38:03 -05:00
parent c33dedf10b
commit ff3916ab41
4 changed files with 96 additions and 21 deletions

View file

@ -1,2 +1,3 @@
dockergen: docker-gen -watch -notify "nginx -s reload" /app/nginx.tmpl /etc/nginx/conf.d/default.conf
dockergen2: docker-gen -watch /app/index.tmpl /usr/share/nginx/html/index.html
nginx: nginx

View file

@ -48,15 +48,53 @@ services:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
networks:
- webproxy
whoami:
image: jwilder/whoami
environment:
- VIRTUAL_HOST=whoami.local
networks:
webproxy:
```
```shell
$ docker-compose up
```
Deploy a service
```yaml
version: '2'
services:
whoami:
image: jwilder/whoami
environment:
- VIRTUAL_HOST=whoami.local
networks:
- nginx-proxy_webproxy
networks:
nginx-proxy_webproxy:
external: true
```
```shell
$ docker-compose up
$ curl localhost
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>List</title>
</head>
<body>
<ul>
<li>
<a target="_blank" href="http://whoami.local">whoami.local</a>
</li>
</ul>
</body>
</html>
$ curl -H "Host: whoami.local" localhost
I'm 5b129ab83266
```

24
index.tmpl Normal file
View file

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>List</title>
</head>
<body>
<ul>
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
{{ $host := trim $host }}
{{ $is_regexp := hasPrefix "~" $host }}
{{ $upstream_name := when $is_regexp (sha1 $host) $host }}
<li>
<a target="_blank" href="http://{{ $host }}">{{ $host }}</a>
</li>{{ end }}
</ul>
</body>
</html>

View file

@ -115,6 +115,18 @@ server {
}
{{ end }}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
{{ $host := trim $host }}