Skip to content

Emphazise the need for properly setup environment variables #530

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

Merged
merged 1 commit into from
Jun 5, 2023
Merged
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
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ $ docker run -d --name nginx-gen --volumes-from nginx \
-t nginxproxy/docker-gen -notify-sighup nginx -watch -only-exposed /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
```

Start a container, taking note of any Environment variables a container expects. See the top of a template for details.

```
$ docker run --env VIRTUAL_HOST='example.com' --env VIRTUAL_PORT=80 ...
```

===

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

### Templating

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.
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.

#### Emit Structure

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

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

```
$ docker run -e VIRTUAL_HOST=foo.bar.com -t ...
$ docker run -e VIRTUAL_HOST=foo.bar.com -e VIRTUAL_PORT=80 -t ...
```

If you wanted to run docker-gen directly on the host, you could do it with:
Expand Down
3 changes: 3 additions & 0 deletions templates/dnsmasq.hosts.conf.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{{/* Simple dnsmasq template generating host entries */}}
{{/* Domains are hard-coded, replace 'docker.comany.com' below */}}

{{$domain := "docker.company.com"}}
{{range $key, $value := .}}
# {{ $value.Name }} ({{$value.ID}} from {{$value.Image.Repository}})
Expand Down
1 change: 1 addition & 0 deletions templates/etcd.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{/* etcd template to generate registration script */}}

#!/bin/bash

Expand Down
1 change: 1 addition & 0 deletions templates/fluentd.conf.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{/* Generates fluentd configuration entries */}}

## File input
## read docker logs with tag=docker.container
Expand Down
4 changes: 4 additions & 0 deletions templates/logrotate.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{{/* Generate logrotate snippets for logrotate based on files listed in */}}
{{/* the comma separated environment variable LOG_FILES */}}
{{/* e.g. docker run --env='/var/log/messages,/var/log/lastlog' ... */}}

{{ range $index, $value := $ }}
{{ $logs := $value.Env.LOG_FILES }}
{{ if $logs }}
Expand Down
9 changes: 7 additions & 2 deletions templates/nginx.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{{/* default nginx configuration template */}}
{{/* Generate a configuration file based on the containers mandatory */}}
{{/* VIRTUAL_HOST environment variable and the exposed ports. If multiple */}}
{{/* ports are exposed, the first one is used, unless set with VIRTUAL_PORT */}}

server {
listen 80 default_server;
server_name _; # This is just an invalid value which will never trigger on a real hostname.
Expand All @@ -13,7 +18,7 @@ upstream {{ $host }} {

{{ $addrLen := len $value.Addresses }}
{{ $network := index $value.Networks 0 }}

{{/* If only 1 port exposed, use that */}}
{{ if eq $addrLen 1 }}
{{ with $address := index $value.Addresses 0 }}
Expand Down Expand Up @@ -62,4 +67,4 @@ server {
proxy_set_header Connection "";
}
}
{{ end }}
{{ end }}