HUB
Sign inSign up
varnish logo

eeacms/varnish

By eeacms

•Updated 8 days ago

Varnish docker image with support for dynamic backends, Rancher DNS, auto-configure and reload.

Image
26

1M+

eeacms/varnish repository overview

⁠Varnish Docker image

Varnish docker image with support for dynamic backends, Rancher DNS, auto-configure and reload.

This image is generic, thus you can obviously re-use it within your non-related EEA projects.

  • Debian 13 (trixie) - since 9.x, based on the official Debian varnish image (7.x and 8.x are Alpine)
  • Varnish 9.1.0
  • Expose 80, 8443
⁠Stable and immutable tags

See older versions⁠

⁠Changes

⁠Base docker image

⁠Source code

⁠Installation

  1. Install Docker⁠.

⁠Variables

  • VARNISH_HTTP_PORT - varnish port
  • VARNISH_HTTPS_PORT - varnish ssl port
  • VARNISH_SIZE - varnish cache size
  • AUTOKILL_CRON - Varnish re-create crontab, will force a recreation of the container. Uses UTC time, format is linux crontab - for example - 0 2 * * * is 02:00 UTC each day"
  • VARNISH_CFG_CONTENT - Multiline variable that will be written in the default.vcl file

⁠Usage

⁠Using VARNISH_CFG_CONTENT

See docker-compose.yml⁠.

⁠Extend the image with a custom varnish.vcl file

The default.vcl file provided with this image is bare and only contains the marker to specify the VCL version. If you plan on using a more elaborate base configuration in your container and you want it shipped with your image, you can extend the image in a Dockerfile, like this:

FROM eeacms/varnish
COPY varnish.vcl /etc/varnish/default.vcl

and then run

$ docker build -t varnish-custom /path/to/Dockerfile

⁠How to add docker environment variables in varnish.vcl

  1. Choose relevant variable name, starting with VARNISH_ - eg. VARNISH_EXAMPLE

  2. Add default value in Dockerfile

    ENV VARNISH_EXAMPLE="GET"

  3. Add variable in <> in varnish.vcl

    set req.http.X-Varnish-Routed = "<VARNISH_EXAMPLE>";

  4. Add description in Readme.md

⁠Using a read-only volume for the vcl template files - /varnish-config

The volume /varnish-config will be used to store the read only vcl template configuration files. They will be copied with the same structure to /etc/varnish, where the variable substitution will be done.

⁠Rancher integration

Use dynamic.director to integrate varnish in rancher DNS - if a backend containers are changed, it knows to get the latest list of IPs automatically.

  new cluster = dynamic.director(port = "<VARNISH_BACKEND_PORT>", ttl = <VARNISH_DNS_TTL>);

vmod_dynamic is not part of the official varnish 9 image; this image builds it from the libvmod-dynamic⁠ 9.1 branch.

⁠Upgrading from varnish 7/8

The image is now Debian based instead of Alpine. If you extend it, install packages with apt-get instead of apk, and note that /bin/sh is dash, not busybox ash (for example echo -e is not supported, use printf).

Varnish 9 removed the synthetic() function. Assign the body directly instead - this also works on varnish 7 and 8:

  # vcl_synth
  set resp.body = {"<html>...</html>"};
  # vcl_backend_error
  set beresp.body = {"<html>...</html>"};
⁠Example:

You can use plone-varnish⁠ as an example of usage.

⁠Upgrade
$ docker pull eeacms/varnish

The Initial Owner of the Original Code is European Environment Agency (EEA). All Rights Reserved.

The Original Code is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

⁠Funding

European Environment Agency (EU)⁠

Tag summary

Content type

Image

Digest

sha256:b6ade5632…

Size

91.4 MB

Last updated

9 days ago

docker pull eeacms/varnish