Skip to content

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

Notifications You must be signed in to change notification settings

manios/docker-varnish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Supported tags and respective Dockerfile links

build status badge Docker pulls badge Docker 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.4.0 revision 13f137934ec1cf14af66baf7896311115ee35598)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2019 Varnish Software AS
Debug: Version: varnish-6.4.0 revision 13f137934ec1cf14af66baf7896311115ee35598
Debug: Platform: Linux,4.4.0-174-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 varnishd parameters 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

About

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

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published