8000 GitHub - njmittet/alpine-varnish: Docker image for running Varnish. Based on Alpine Linux.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

njmittet/alpine-varnish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

alpine-varnish

A Docker image running Varnish HTTP Cache, based on Alpine Linux.

This README only aims at getting you up and running with the Docker image, and documents only a very basic usage of Varnish. Consult the Varnish Documentation for more details.

See the image on Docker Hub.

Versions

The image is based on alpine-3 and provides Varnish Cache 6.5.1, which has EOL date 2022-09-15.

TLS Termination

This image is created for development purposes (e.g for testing how load balanced backends behaves), and does not support SSL/TLS termination. See How to configure Varnish with SSL termination using the Hitch TLS proxy for details.

If you require TLS termination, use the official Varnish Docker image instead.

Defaults

  • Varnish listens on port 80.
  • The default.vcl assumes a backend listening on localhost:8080.
  • The default.vcl location us /etc/varnish/default.vcl

Environmental Variables

The images uses the following environmental variables. See the varnishd documentation for more details.

VCL_DIR '/etc/varnish'
VCL_FILE 'default.vcl'
VARNISH_CACHE_SIZE 64m
VARNISH_ADDRESS '0.0.0.0'
VARNISH_PORT 80

Dummy Backend

A dummy backend JSON REST API is provided in order to ease testing:

  1. Install JSON Server or any other equivalent dummy backend tool.
  2. Serve the file using:
# The default JSON server port is 3000, but the default VCL-file assumes a backend running on port 8080.
json-server --watch backend/db.json --port 8080

Verify that the dummy backend is running with:

curl localhost:8080/posts
# Should return:
[
  {
    "id": 1,
    "title": "json-server",
    "author": "typicode"
  }
]

Usage

The image can be used directly or as a base for you own image.

Use Directly

Out of the box the image assumes a backend on localhost:8080, which implies that the docker image has to be on the same network as the host. That works well for testing, but be aware of port collisions.

docker run -it --rm --name myvarnish --network host njmittet/alpine-varnish

Verify that Varnish works by requesting on port 80:

curl localhost/posts
# Should return:
[
  {
    "id": 1,
    "title": "json-server",
    "author": "typicode"
  }
]

Run with a different VCL-file using bind mounts:

# Replace the default.vcl file.
docker run -it --rm --name myvarnish --network host -v $(pwd)/alt.vcl:/etc/varnish/default.vcl:ro njmittet/alpine-varnish

# Use a VCL file with a different name.
docker run -it --rm --name myvarnish --network host -v $(pwd)/alt.vcl:/etc/varnish/alt.vcl:ro -e VCL_FILE='alt.vcl' njmittet/alpine-varnish

To change the port Varnish listens on, both the Varnish port and the port exposed by Docker must be changed:

docker run -it --rm --name myvarnish --network host -e VARNISH_PORT=9000 --expose=9000 njmittet/alpine-varnish

Use as Base Image

Create an image containing your own VCL-file by creating a Dockerfile with the following content:

FROM njmittet/alpine-varnish:latest
COPY alt.vcl $VCL_DIR/default.vcl
# Build and run the container.
docker build -t myvarnish .
docker run -it --rm --name myvarnish --network host myvarnish

VCL Examples

See the examples for a cluster example. Consult the Varnish VCL Examples for a great list of other examples.

About

Docker image for running Varnish. Based on Alpine Linux.

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0