varnish / docker-varnish

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

Varnish is running but throws ‘Could not get hold of varnishd’ when I run varnishlog #30

Closed jbrunetext closed 3 years ago

jbrunetext commented 3 years ago

Possible Solution

Possible create files with different permissions.

Steps to Reproduce (for bugs)

Pull image for K8s from varnish docker registry FROM varnish:6.0

Use the user varnish, and add his following param : -a /tmp/listen.sock,HTTP,user=varnish,group=varnish,mode=660

varnishhist ,

Start it with the docker -compose. Your Environment: Version used: Varnish 6.0 Operating System and version: Ubuntu Xenial Source of binary packages used (if any) Built from varnish image 6.0

I faced an issue when i use varnishlog.

USER varnish CMD ["bash", "-c", "varnishd -F -P /tmp/varnish.pid -n /tmp/varnish -a /tmp/listen.sock,HTTP,user=varnish,group=varnish,mode=660 -p http_req_hdr_len=65536 -p http_req_size=98304 -p workspace_backend=256k -p workspace_client=256k -p shm_reclen=1024 -p max_retries=1 & varnishncsa -b -c -t off"]

my varnish works and it is responsive but i can not do an varnishlog.same thing with varnishncsa

Did i make something wrong in my config ?

gquintard commented 3 years ago

I believe this is the same as https://github.com/varnishcache/varnish-cache/issues/3607 , closing

jbrunetext commented 3 years ago

Hello @gquintard i made the change in my dockerFile like you say

#Varnish stage
FROM varnish:6.0

RUN apt-get update && apt-get install -y libpcap-dev libcap2-bin

COPY docker/varnish/conf/default.vcl /etc/varnish/default.vcl

RUN setcap 'cap_net_bind_service=+ep' /usr/sbin/varnishd
RUN usermod -a -G varnish varnishlog
RUN chown -R varnish:varnish /var/lib/varnish
USER varnish

CMD ["bash", "-c", "varnishd -F -f /etc/varnish/default.vcl -n /tmp/varnish -a /tmp/listen.sock,HTTP,user=varnish,group=varnish,mode=660 -p http_req_hdr_len=65536 -p http_req_size=98304 -p workspace_backend=256k -p workspace_client=256k -p shm_reclen=1024 -p max_retries=1 & varnishncsa -n /tmp/varnish -b -c -t off"]

i'm still suck with my issue VSM: Could not get hold of varnishd, is it running?

It looks like varnishlog is not pointing to the correct directory, or has not access to it.

Any helps would be nice

gquintard commented 3 years ago

There's most probably something wrong with your k8s setup, your VCL works for me. I'm using these two files: https://filebin.varnish-software.com/s2zyb7wfg665wzbr Dockerfile at the root of my workdir, and default.vcl indocker/varnish/conf`.

Then:

$ docker build --pull  -t foo .
<some boring logs>
$ docker run -v /tmp:/tmp/ foo
Warnings:
VCL compiled.

Debug: Version: varnish-6.0.7 revision 525d371e3ea0e0c38edd7baf0f80dc226560f26e
Debug: Platform: Linux,5.11.16-arch1-1,x86_64,-jnone,-sdefault,-sdefault,-hcritbit
Debug: Child (23) Started
Log abandoned (vsl)
Info: Child (23) said Child starts
Log reacquired

And if I try to curl from another terminal, it works:

$ sudo curl --unix-socket /tmp/listen.sock http:/foo -I
HTTP/1.1 503 Backend fetch failed
Date: Mon, 03 May 2021 17:13:54 GMT
Server: Varnish
Content-Type: text/html; charset=utf-8
Retry-After: 5
X-Varnish: 5
Age: 0
Via: 1.1 varnish (Varnish/6.0)
Content-Length: 278
Connection: keep-alive

And it shows up in the first terminal too:

- - - [03/May/2021:17:13:51 +0000] "HEAD http://foo/ HTTP/1.1" 503 0 "-" "curl/7.76.1"
0.0.0.0 - - [03/May/2021:17:13:51 +0000] "HEAD http://foo/ HTTP/1.1" 503 0 "-" "curl/7.76.1"

Can you test this locally so we know if it's a docker issue or a k8s one?

jbrunetext commented 3 years ago

it's working for me now