6.4.0
,6.4
,latest
(6.4.0/Dockerfile)5.2.1
,5.2
(5.2.1/Dockerfile)
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.
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
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 issome-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
You can configure Varnish daemon by overriding the following environmental variables:
- VCL_CONFIG
- Default value:
/etc/varnish/default.vcl
- Default value:
- CACHE_SIZE
- Default value:
64m
(64 megabytes)
- Default value:
- VARNISHD_PARAMS :
- Default value:
-p default_ttl=3600 -p default_grace=3600
For all available values you can instruct officialvarnishd
parameters documentation.
- Default value:
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
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
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