manios/varnish

By manios

Updated almost 5 years ago

Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy.

Image

1.5K

Supported tags and respective Dockerfile links

build status badgeDocker pulls badgeDocker stars badge

What is Varnish?

Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture. A high level overview of what Varnish does can be seen in this video. More information: Varnish official page.

Varnish logo

How to use this image

To use this container, you will need to provide your custom config.vcl (which is usually the case).

docker run -d \
  --name some-varnish \
  manios/varnish

To test if the container has started you can issue:

docker logs -f --tail 200 some-varnish

The expected output may look like the following:

/etc/varnish is not empty. We are ok to go.
/etc/varnish/secret file does not exist. Creating a new one.
0+1 records in
0+1 records out
104 bytes copied, 0.000431003 s, 241 kB/s
/etc/varnish/secret successfully created!
varnishd (varnish-6.3.2 revision 6870fd661a2b42c2e8adad838b5d92a71f27dccd)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2019 Varnish Software AS
Debug: Version: varnish-6.3.2 revision 6870fd661a2b42c2e8adad838b5d92a71f27dccd
Debug: Platform: Linux,4.4.0-166-generic,x86_64,-junix,-smalloc,-sdefault,-hcritbit
Debug: Child (20) Started
Info: Child (20) said Child starts

Override default configuration

Varnish configuration is stored by default to /etc/varnish/default.vcl file. You can either use docker volumes or a custom Dockerfile to override default configuration.

  • Using volumes:

    docker run -d \
          --name some-varnish \
          -v /hostdir/varnish:/etc/varnish \
          -p 6081:6081 
          manios/varnish:testo
    

    The above command creates a new container which:

    • --name some-varnish: it's name is some-varnish
    • -v /etc/varnish:/etc/varnish \: It mounts the container /etc/varnish directory to /hostdir/varnish host directory and copies the initial configuration if directory does not exist or is empty.
    • -p 6081:6081: It exposes port 6081.
  • Using a custom Dockerfile:

    FROM manios/varnish:latest
    
    COPY myconf.vcl /mydir/myconf.vcl
    

    Then run:

    docker build -t myvarnish:6.1 . \
    && docker run -d \
        --name some-varnish \
        -e VCL_CONFIG=/mydir/myconf.vcl \
        -p 6081:6081 \
        myvarnish:6.1
    

Environmental variables

You can configure Varnish daemon by overriding the following environmental variables:

  • VCL_CONFIG
    • Default value: /etc/varnish/default.vcl
  • CACHE_SIZE
    • Default value: 64m (64 megabytes)
  • VARNISHD_PARAMS :
    • Default value: -p default_ttl=3600 -p default_grace=3600 For all available values you can instruct official varnishdparameters documentation.

For example, providing we want to have a container with:

  • Configuration file: /opt/manios.vcl
  • Cache size: 1GB
  • TTL: 86400 seconds (1 day)
  • Grace period: 5 seconds
  • Expose port 80 we will run the command:
    docker run -d \    --name some-varnish \    -e VCL_CONFIG=/opt/manios.vcl \    -e CACHE_SIZE=1g \    -e 'VARNISHD_PARAMS=-p default_ttl=86400 -p default_grace=5' \    -p 80:6081 \    manios/varnish
    

Get Statistics

You can display statistics from the running container varnishd instance using varnishstat utility command. For all available options you can refer to the official documentation.

docker exec -it some-varnish varnishstat

See live Varnish Logs

You can display live logs from the running container varnishd instance using varnishlog utility command. For all available options you can refer to the official documentation.

docker exec -it myvarnish varnishlog

Docker Pull Command

docker pull manios/varnish