This is a very flexible nginx image, with support for several types of applications. It's heavy, because it's based on helder/nginx-extras, but it's full featured, and thanks to docker, you only need it once.
Based on perusio's work.
Virtual host templates
Thanks to the provided entrypoint.sh and Jinja, we're able to have a virtual host configurable at runtime using environment variables. This is a great way to reuse the same image for many different purposes.
To get a list of the available types of apps included:
docker run -t --rm helder/nginx ls -1 /etc/nginx/templates/vhost
Run a static website (default):
docker run -d -v "$PWD:/usr/src/app" -p 80:80 helder/nginx web_static
If you don't provide
/usr/src/app, Nginx's welcome message is show:
docker run -d -p 80:80 helder/nginx nginx_welcome
If you want your files in a different path:
docker run -d -v "$PWD:/web" -e CONF_ROOT=/web -p 80:80 helder/nginx web_static
Run a drupal website:
docker run -d -v "$PWD:/usr/src/app" helder/php php docker run -d --volumes-from php --link php -e CONF_APP=drupal -e CONF_UPSTREAM=php:9000 -p 80:80 helder/nginx web_drupal
How to chose an app
Anything listed in the
templates/vhost folder of nginx is an app (you can add your own).
To define which you want, set the environment variable
Bypass template system
When an app is chosen, the rendered template will be written to
If the file exists, nothing is done so if you don't want to use the template system,
you can bypass it completely by adding your own file.
FROM helder/nginx COPY mysite.conf /etc/nginx/sites-enabled/default.conf
How to work with the templates
Thanks to Jinja, templates are extensible. Here's an overview of the hierarchy:
. └── default ├── django ├── flask └── php ├── bolt ├── drupal │ └── drupal6 ├── joomla ├── symfony1 └── wordpress
All of these are valid values for
Configurable with environment variables
Any environment variable starting with
CONF_ will be provided to the template, without
the prefix and lowercase.
CONF_MY_SETTING would be
my_setting in the template.
Variables found in a template, are also available for every template that extends it.
Type of app. See list of files in
/etc/nginx/templats/vhost/for possible values.
Not really used anywhere but can be used in your own templates and will affect de value
If you want a unix socket in the upstream, you can override it's name. Leave the
extension out because it will be added by default by
The upstream socket is shared from a volume (e.g. php) by default. If that's not
the case, override this setting.
Location for the
rootdirective in Nginx. No trailing slash because the actual value of the
rootdirective will be
Default: empty or...
Value to append to
CONF_ROOTfor the nginx's
rootdirective. No leading slash, see
CONF_ROOTdescription. Useful in a project with a subfolder as public facing (e.g. symfony).
If this is the only vhost in this container running nginx, there's no sense in setting your
name_server. But if you need it somehow...
The default is to send access logs to stdout, but you can use this variable to send your
app's logs to another file or shut them off entirely.
Add your own template
Build a new image with your own jinja template.
FROM helder/nginx COPY myapp.jinja /etc/nginx/templates/vhost/myapp
Full example with docker compose
Drupal 8 project with public facing folder in
version: '2' services: web: image: helder/nginx ports: - 80 volumes_from: - php environment: - CONF_APP=drupal - CONF_PUBLIC=web - CONF_UPSTREAM=php:9000 php: image: helder/php:5.6 links: - db - mail volumes: - ./:/usr/src/app working_dir: /usr/src/app db: image: mysql:5.5 ports: - 3306 mail: image: helder/mailcatcher ports: - 80