varnish / docker-varnish

Official docker image
https://hub.docker.com/_/varnish
82 stars 34 forks source link

Provide logging as option env variable #25

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hi guys,

Hope you are all well !

Is it possible to add logging to the docker varnish container ?

Could not find how to write the acces.log/error.log file. ^^

Cheers, Luc Michalski

gquintard commented 3 years ago

Hi,

this should help: https://docs.varnish-software.com/tutorials/vsl-query and https://varnish-cache.org/docs/trunk/reference/vsm.html

TL;DR: use a sidecar mounting /var/lib/varnish (this is where the shared memory log is), and run either varnishncsa or varnishlog

batandwa commented 3 years ago

varnishncsa or varnishlog seem to require a running instance varnishd. I get VSM: Could not get hold of varnishd, is it running?

Am I doing something wrong?
Here's my compose file:

services:
  varnish:
    image: varnish:6.6
    volumes:
      - cache-logs:/var/lib/varnish
  varnish-log:
    image: varnish:6.6
    volumes:
      - cache-logs:/var/lib/varnish
    entrypoint: varnishncsa
gquintard commented 3 years ago

Hi @batandwa

The issue is that both varnishd and varnishncsa will look into /var/lib/varnish/$HOSTNAME to write/read the logs. But as they are in different containers, their hostnames are different. The quick fix for you is to use -n to tell them exactly where to look:

services:
  varnish:
    image: varnish:6.6
    volumes:
      - cache-logs:/var/lib/varnish
    command: [ "-n", "/var/lib/varnish" ]
  varnish-log:
    image: varnish:6.6
    volumes:
      - cache-logs:/var/lib/varnish
    entrypoint: varnishncsa
    command: [ "-n", "/var/lib/varnish" ]

volumes:
  cache-logs:
    driver: local
    driver_opts:
      type: tmpfs
      device: tmpfs

I'm reopening this ticket, we need to update the image to make this way easier, very possibly by forcing that -n parameter by default

gquintard commented 3 years ago

https://github.com/docker-library/official-images/pull/9914#event-4558416945

we are now a bit clever and force the -n argument to the beginning of varnish* commands, which should solve all your issues here