Skip to content

Commit d8a03eb

Browse files
Run update.sh
1 parent 358d2f2 commit d8a03eb

2 files changed

Lines changed: 78 additions & 63 deletions

File tree

bash/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ WARNING:
2424

2525
# Supported tags and respective `Dockerfile` links
2626

27-
- [`devel-20260309`, `devel`, `devel-20260309-alpine3.23`, `devel-alpine3.23`](https://github.com/tianon/docker-bash/blob/5b559e99a3edb62532ae3a1c4ed7de7ed7c0c10c/devel/Dockerfile)
27+
- [`devel-20260324`, `devel`, `devel-20260324-alpine3.23`, `devel-alpine3.23`](https://github.com/tianon/docker-bash/blob/d75654453472c202837574b8fd8ea7685af5592a/devel/Dockerfile)
2828

2929
- [`5.3.9`, `5.3`, `5`, `latest`, `5.3.9-alpine3.23`, `5.3-alpine3.23`, `5-alpine3.23`, `alpine3.23`](https://github.com/tianon/docker-bash/blob/59999c513d9e7bddb3972d38aa112af045cb0e80/5.3/Dockerfile)
3030

varnish/README.md

Lines changed: 77 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,51 @@ Varnish is an HTTP accelerator designed for content-heavy dynamic web sites as w
6161

6262
# How to use this image.
6363

64+
```console
65+
$ docker run -p 8080:80 --ulimit memlock=-1:-1 --tmpfs /var/lib/varnish/varnishd:exec varnish
66+
```
67+
68+
You can then visit [http://localhost:8080](http://localhost:8080) with your browser and be greeted by the default landing page.
69+
70+
**Note:** while the `--ulimit` and `--tmpfs` options aren't necessary, they are greatly recommended. More details are available at the end of this page.
71+
6472
## Basic usage
6573

66-
### Using `VARNISH_BACKEND_HOST` and `VARNISH_BACKEND_PORT`
74+
### Simple cache
6775

68-
You just need to know where your backend (the server that Varnish will accelerate) is:
76+
The default Varnish configuration will read the `VARNISH_BACKEND_HOST` environment variable which should be an HTTP or HTTPS URL, for example:
6977

7078
```console
71-
# we define VARNISH_BACKEND_HOST/VARNISH_BACKEND_PORT
72-
# our workdir has to be mounted as tmpfs to avoid disk I/O,
73-
# and we'll use port 8080 to talk to our container (internally listening on 80)
7479
$ docker run \
75-
-e VARNISH_BACKEND_HOST=example.com -e VARNISH_BACKEND_PORT=80 \
80+
--ulimit memlock=-1:-1 \
7681
--tmpfs /var/lib/varnish/varnishd:exec \
7782
-p 8080:80 \
83+
-e VARNISH_BACKEND_HOST=https://example.com/ \
7884
varnish
7985
```
8086

81-
From there, you can visit `localhost:8080` in your browser and see the example.com homepage.
87+
By default, Varnish is extremely careful regarding what it can and cannot cache by looking at the [client request](https://www.varnish-software.com/developers/tutorials/varnish-builtin-vcl/#1-vcl_recv) and at the [backend response](https://www.varnish-software.com/developers/tutorials/varnish-builtin-vcl/#11-vcl_backend_response).
8288

83-
### Using a VCL file
89+
Notably, Varnish will not cache if:
90+
91+
- the request is not a `GET` or `HEAD`
92+
- the request contains an `Authorization` or `Cookie` header
93+
- the response status is not cacheable (i.e., not a 2xx or 4xx response)
94+
- the response contains a `Set-Cookie` header
95+
- the response contains headers indicating it is uncacheable
96+
97+
These rules can, of course, be overridden by providing your own `VCL` file, as explained in the next section.
98+
99+
### Custom caching logic
84100

85101
If you already have a VCL file, you can directly mount it as `/etc/varnish/default.vcl`:
86102

87103
```console
88-
# we need the configuration file at /etc/varnish/default.vcl,
89-
# our workdir has to be mounted as tmpfs to avoid disk I/O,
90-
# and we'll use port 8080 to talk to our container (internally listening on 80)
91104
$ docker run \
92-
-v /path/to/default.vcl:/etc/varnish/default.vcl:ro \
105+
--ulimit memlock=-1:-1 \
93106
--tmpfs /var/lib/varnish/varnishd:exec \
94107
-p 8080:80 \
108+
-v /path/to/default.vcl:/etc/varnish/default.vcl:ro \
95109
varnish
96110
```
97111

@@ -106,12 +120,16 @@ COPY default.vcl /etc/varnish/
106120
Place this file in the same directory as your `default.vcl`, run `docker build -t my-varnish .`, then start your container:
107121

108122
```console
109-
$ docker --tmpfs /var/lib/varnish/varnishd:exec -p 8080:80 my-varnish
123+
$ docker \
124+
--ulimit memlock=-1:-1 \
125+
--tmpfs /var/lib/varnish/varnishd:exec \
126+
-p 8080:80 \
127+
my-varnish
110128
```
111129

112130
## Reloading the configuration
113131

114-
The images all ship with [varnishreload](https://github.com/varnishcache/pkg-varnish-cache/blob/master/systemd/varnishreload#L42) which allows you to easily update the running configuration without restarting the container (and therefore losing your cache). At its most basic, you just need this:
132+
The images all ship with [varnishreload](https://github.com/varnish/all-packager/blob/809d3c098d1cb84d1b85e18573121a3a3720c898/varnish/systemd/varnishreload#L48-L82) which allows you to easily update the running configuration without restarting the container (and therefore losing your cache). At its most basic, you just need this:
115133

116134
```console
117135
# update the default.vcl in your container
@@ -120,42 +138,70 @@ docker cp new_default.vcl running_container:/etc/varnish/default.vcl
120138
docker exec running_container varnishreload
121139
```
122140

123-
Note that `varnishreload` also supports reloading other files (it doesn't have to be `default.vcl`), labels (`l`), and garbage collection of old labeles (`-m`) among others. To know more, run
141+
Note that `varnishreload` also supports reloading other files (it doesn't have to be `default.vcl`), labels (`-l`), and garbage collection of old labels (`-m`), among others. To learn more, run
142+
143+
```console
144+
$ docker run --rm varnish varnishreload -h
145+
```
146+
147+
## File server
148+
149+
Using the included [vmod-fileserver](https://github.com/varnish-rs/vmod-fileserver), Varnish can be used as a file server. Just mount the directory you want to expose into the `/var/www/html` directory and set the `VARNISH_FILESERVER` variable to `true`:
124150

125151
```console
126-
docker run varnish varnishreload -h
152+
$ docker run \
153+
--ulimit memlock=-1:-1 \
154+
--tmpfs /var/lib/varnish/varnishd:exec \
155+
-p 8080:80 \
156+
-v /dir/to/expose:/var/www/html:ro \
157+
-e VARNISH_FILESERVER=true \
158+
varnish
127159
```
128160

129-
## Additional configuration
161+
**Note:** Varnish will reply with an empty 200 when trying to access folders instead of individual files.
162+
163+
## Environment variables
164+
165+
### Backend address (`VARNISH_BACKEND_HOST`)
166+
167+
Set the backend address and protocol as explained above. This only works with the provided `VCL`, i.e. if you don't mount an `/etc/varnish/default.vcl` file, and if you don't set `VARNISH_VCL_FILE`
168+
169+
### File server mode (`VARNISH_FILESERVER`)
170+
171+
Also only valid with the default `VCL`. If `VARNISH_BACKEND_HOST` is unset and `VARNISH_FILESERVER` is set, Varnish will act as a server, using `/var/www/html` as its source.
130172

131-
### Cache size (VARNISH_SIZE)
173+
### Cache size (`VARNISH_SIZE`)
132174

133175
By default, the containers will use a cache size of 100MB, which is usually a bit too small, but you can quickly set it through the `VARNISH_SIZE` environment variable:
134176

135177
```console
136178
$ docker run --tmpfs /var/lib/varnish/varnishd:exec -p 8080:80 -e VARNISH_SIZE=2G varnish
137179
```
138180

139-
### Listening ports (VARNISH_HTTP_PORT/VARNISH_PROXY_PORT)
181+
### Listening ports (`VARNISH_HTTP_PORT`/`VARNISH_PROXY_PORT`)
140182

141-
Varnish will listen to HTTP traffic on port `80`, and this can be overridden by setting the environment variable `VARNISH_HTTP_PORT`. Similarly, the variable `VARNISH_PROXY_PORT` (defaulting to `8443`) dictate the listening port for the [PROXY protocol](https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt) used notably to interact with [hitch](https://hub.docker.com/_/hitch) (which, coincidentally, uses `8443` as a default too!).
183+
Varnish will listen to HTTP traffic on port `80`, and this can be overridden by setting the environment variable `VARNISH_HTTP_PORT`. Similarly, the variable `VARNISH_PROXY_PORT` (defaulting to `8443`) dictates the listening port for the [PROXY protocol](https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt) used notably to interact with [hitch](https://hub.docker.com/_/hitch) (which, coincidentally, uses `8443` as a default too!).
142184

143185
```console
144-
# instruct varnish to listening to port 7777 instead of 80
186+
# instruct varnish to listen on port 7777 instead of 80
145187
$ docker run --tmpfs /var/lib/varnish/varnishd:exec -p 8080:7777 -e VARNISH_HTTP_PORT=7777 varnish
146188
```
147189

148-
### VCL file path
190+
### VCL file (`VARNISH_VCL_FILE`)
149191

150192
The default Varnish configuration file is `/etc/varnish/default.vcl`, but this can be overridden with the `VARNISH_VCL_FILE` environment variable. This is useful if you want a single image that can be deployed with different configurations baked in it.
151193

152194
### Extra arguments
153195

154-
Additionally, you can add arguments to `docker run` after `varnish`, if the first argument starts with a `-`, the whole list will be appendend to the [default command](https://github.com/varnish/docker-varnish/blob/master/fresh/debian/scripts/docker-varnish-entrypoint):
196+
Additionally, you can add arguments to `docker run` after `varnish`, if the first argument starts with a `-`, the whole list will be appended to the [default command](https://github.com/varnish/docker-varnish/blob/master/fresh/debian/scripts/docker-varnish-entrypoint):
155197

156198
```console
157199
# extend the default keep period
158-
$ docker run --tmpfs /var/lib/varnish/varnishd:exec -p 8080:80 -e VARNISH_SIZE=2G varnish -p default_keep=300
200+
$ docker run \
201+
--ulimit memlock=-1:-1 \
202+
--tmpfs /var/lib/varnish/varnishd:exec \
203+
-p 8080:80 \
204+
varnish -p default_keep=300
159205
```
160206

161207
If your first argument after `varnish` doesn't start with `-`, it will be interpreted as a command to override the default one:
@@ -171,49 +217,18 @@ $ docker run varnish varnishd -x parameter
171217
$ docker run varnish varnishd -F -a :8080 -b 127.0.0.1:8181 -t 600 -p feature=+http2
172218
```
173219

174-
## vmods (since 7.1)
175-
176-
As mentioned above, you can use [vmod_dynamic](https://github.com/nigoroll/libvmod-dynamic) for backend resolution. The [varnish-modules](https://github.com/varnish/varnish-modules) collection is also included in the image. All the documentation regarding usage and syntax can be found in the [src/](https://github.com/varnish/varnish-modules/tree/master/src) directory of the repository.
220+
This can notably be used to extract logs using [varnishncsa or varnishlog](https://www.varnish-software.com/developers/tutorials/vsl-cheatsheet/), running `varnishstat -1` to extract metrics, and of course reloading the `VCL` with `varnishreload`.
177221

178-
On top of this, images include [install-vmod](https://github.com/varnish/toolbox/tree/master/install-vmod), a helper script to quickly download, compile and install vmods while creating your own images. Note that images set the `ENV` variable `VMOD_DEPS` to ease the task further.
222+
## Vmods
179223

180-
### Debian
224+
The docker image is built with a collection of "`VCL` modules" or "vmods" that extend Varnish capability. We've already covered `vmod-fileserver` (file backend) and `vmod-reqwest` (dynamic backends), but more are available and can be used in your custom `VCL` with `import <vmod_name>`. Please refer to the documentation of each vmod for more information.
181225

182-
```dockerfile
183-
FROM varnish:7.1
184-
185-
# set the user to root, and install build dependencies
186-
USER root
187-
RUN set -e; \
188-
apt-get update; \
189-
apt-get -y install $VMOD_DEPS /pkgs/*.deb; \
190-
\
191-
# install one, possibly multiple vmods
192-
install-vmod https://github.com/varnish/varnish-modules/releases/download/0.20.0/varnish-modules-0.20.0.tar.gz; \
193-
\
194-
# clean up and set the user back to varnish
195-
apt-get -y purge --auto-remove $VMOD_DEPS varnish-dev; \
196-
rm -rf /var/lib/apt/lists/*
197-
USER varnish
198-
```
226+
# ulimit and tmpfs notes
199227

200-
### Alpine
228+
Varnish uses [memory-mapped files](https://docs.varnish-software.com/varnish-enterprise/installation/#the-shared-memory-log) to log and store metrics for performance reasons. Those files are constantly written to, and to get the most out of your system, you should:
201229

202-
```dockerfile
203-
FROM varnish:7.1-alpine
204-
205-
# install build dependencies
206-
USER root
207-
RUN set -e; \
208-
apk add --no-cache $VMOD_DEPS; \
209-
\
210-
# install one, possibly multiple vmods
211-
install-vmod https://github.com/varnish/varnish-modules/releases/download/0.20.0/varnish-modules-0.20.0.tar.gz; \
212-
\
213-
# clean up
214-
apk del --no-network $VMOD_DEPS
215-
USER varnish
216-
```
230+
- mount the working directory as `tmpfs` to make sure disk I/O isn't a bottleneck; that's what the `--tmpfs` switch does
231+
- allow Varnish to lock those memory-mapped files so they aren't paged out by the kernel; hence the `--ulimit` switch
217232

218233
# Image Variants
219234

0 commit comments

Comments
 (0)