Skip to content

Commit 2d91e42

Browse files
authored
Merge pull request #530 from oliv3r/doc/better_env
Emphazise the need for properly setup environment variables
2 parents 4deba6c + 9748e03 commit 2d91e42

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ $ docker run -d --name nginx-gen --volumes-from nginx \
7676
-t nginxproxy/docker-gen -notify-sighup nginx -watch -only-exposed /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
7777
```
7878

79+
Start a container, taking note of any Environment variables a container expects. See the top of a template for details.
80+
81+
```
82+
$ docker run --env VIRTUAL_HOST='example.com' --env VIRTUAL_PORT=80 ...
83+
```
84+
7985
===
8086

8187
### Usage
@@ -206,7 +212,7 @@ e75a60548dc9 = 1 # a key can be either container name (nginx) or ID
206212

207213
### Templating
208214

209-
The templates used by docker-gen are written using the Go [text/template](http://golang.org/pkg/text/template/) language. In addition to the [built-in functions](http://golang.org/pkg/text/template/#hdr-Functions) supplied by Go, docker-gen uses [sprig](https://masterminds.github.io/sprig/) and some additional functions to make it simpler (or possible) to generate your desired output.
215+
The templates used by docker-gen are written using the Go [text/template](http://golang.org/pkg/text/template/) language. In addition to the [built-in functions](http://golang.org/pkg/text/template/#hdr-Functions) supplied by Go, docker-gen uses [sprig](https://masterminds.github.io/sprig/) and some additional functions to make it simpler (or possible) to generate your desired output. Some templates rely on environment variables within the container to make decisions on what to generate from the template.
210216

211217
#### Emit Structure
212218

@@ -411,10 +417,10 @@ Start nginx-proxy:
411417
$ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock -t nginxproxy/nginx-proxy
412418
```
413419

414-
Then start containers with a VIRTUAL_HOST env variable:
420+
Then start containers with a VIRTUAL_HOST (and the VIRTUAL_PORT if more than one port is exposed) env variable:
415421

416422
```
417-
$ docker run -e VIRTUAL_HOST=foo.bar.com -t ...
423+
$ docker run -e VIRTUAL_HOST=foo.bar.com -e VIRTUAL_PORT=80 -t ...
418424
```
419425

420426
If you wanted to run docker-gen directly on the host, you could do it with:

templates/dnsmasq.hosts.conf.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
{{/* Simple dnsmasq template generating host entries */}}
2+
{{/* Domains are hard-coded, replace 'docker.comany.com' below */}}
3+
14
{{$domain := "docker.company.com"}}
25
{{range $key, $value := .}}
36
# {{ $value.Name }} ({{$value.ID}} from {{$value.Image.Repository}})

templates/etcd.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{/* etcd template to generate registration script */}}
12

23
#!/bin/bash
34

templates/fluentd.conf.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{/* Generates fluentd configuration entries */}}
12

23
## File input
34
## read docker logs with tag=docker.container

templates/logrotate.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
{{/* Generate logrotate snippets for logrotate based on files listed in */}}
2+
{{/* the comma separated environment variable LOG_FILES */}}
3+
{{/* e.g. docker run --env='/var/log/messages,/var/log/lastlog' ... */}}
4+
15
{{ range $index, $value := $ }}
26
{{ $logs := $value.Env.LOG_FILES }}
37
{{ if $logs }}

templates/nginx.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
{{/* default nginx configuration template */}}
2+
{{/* Generate a configuration file based on the containers mandatory */}}
3+
{{/* VIRTUAL_HOST environment variable and the exposed ports. If multiple */}}
4+
{{/* ports are exposed, the first one is used, unless set with VIRTUAL_PORT */}}
5+
16
server {
27
listen 80 default_server;
38
server_name _; # This is just an invalid value which will never trigger on a real hostname.
@@ -13,7 +18,7 @@ upstream {{ $host }} {
1318

1419
{{ $addrLen := len $value.Addresses }}
1520
{{ $network := index $value.Networks 0 }}
16-
21+
1722
{{/* If only 1 port exposed, use that */}}
1823
{{ if eq $addrLen 1 }}
1924
{{ with $address := index $value.Addresses 0 }}
@@ -62,4 +67,4 @@ server {
6267
proxy_set_header Connection "";
6368
}
6469
}
65-
{{ end }}
70+
{{ end }}

0 commit comments

Comments
 (0)