Stijn Bernards
Stijn Bernards

Reputation: 1091

Docker keep hostname available even though container is not running

I've got the following issue while using Docker and Varnish.

My docker-compose.yml file has the following 2 containers defined

varnish:
   image: varnish
   network: test
my-app:
   image: my-app-image
   network: test

My varnish VCL has the following config:

backend myApp {
    .host = "my-app";
    .port = "8080";
    .first_byte_timeout = 300s;
    .probe = {
        .url = "/percolate-health-check";
        .timeout = 1s;
        .interval = 4s;
        .window = 5;
        .threshold = 3;
    }
}

backend fallback { ...fallback backend settings }

Now the current issue I'm experiencing is. container my-app goes down. Network name my-app is also gone. This in turn crashes Varnish because my-app cannot be resolved.

Is there some way for a Docker hostname keep existing even though the container is down?
Or how should I handle this issue with Varnish / Docker.

Thanks!

Upvotes: 0

Views: 591

Answers (1)

Thijs Feryn
Thijs Feryn

Reputation: 4808

When a backend is no longer available, Varnish will usually not crash. Instead an HTTP 503 error will be returned.

Grace mode

If there's no fallback container you can use grace mode to keep serving stale data while the backend is down. Have a look at https://varnish-cache.org/docs/6.0/users-guide/vcl-grace.html#misbehaving-servers to see a VCL example.

Directors

If you do have a fallback backend, or just multiple backends in general, you can use directors to loadbalance between the backends: https://varnish-cache.org/docs/6.0/users-guide/vcl-backends.html#directors.

There area many types of directors. See https://varnish-cache.org/docs/6.0/reference/vmod_generated.html#varnish-directors-module for an overview

Upvotes: 1

Related Questions