Varnish uses /etc/varnish/default.vcl
as the location of its VCL configuration. In this configuration you'll find a backend definition along with a set of caching policies.
The default backend has the following configuration:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
This configuration assumes that the backend runs locally on port 8080
.
In a Docker context that's not realistic because every service runs in its own container. That's why you need to modify your VCL file.
The best way to do this is by leveraging Volume mapping, which is also part of the screenshot you attached.
Make sure there's a VCL file on the host system and mount it into /etc/varnish/default.vcl
of your Varnish container.
The .host
and .port
attributes should refer to the system you're trying to proxy to.
That will allow Varnish to connect to the right system and cache the HTTP responses.
If you still have the same error after adjusting, please have a look at the following tutorial: https://www.varnish-software.com/developers/tutorials/troubleshooting-varnish/#backend-errors . This will help you debug backend errors using a varnishlog
command.
Side note: even if you can properly connect to a backend, there's no guarantee that Varnish will cache HTTP responses. Varnish has a built-in VCL behavior that describes what can be cached and what cannot be cached. See https://www.varnish-software.com/developers/tutorials/varnish-builtin-vcl/ for a tutorial on built-in VCL.