A Docker image for Caddy. This image includes the git plugin. Plugins can be configured via the plugins
build arg.
Check abiosoft/caddy:builder for generating cross-platform Caddy binaries.
This image is built from source code. As such, it is subject to the project's Apache 2.0 license, but it neither contains nor is subject to the EULA for Caddy's official binary distributions.
This project is a fork of abiosoft/caddy-docker.
It contains an additional plugin (http.filter) and follows its own release schedule.
The default behaviour is the same as previously, the configuration is taken from /etc/Caddyfile.
If Environment Variable CADDY_GENERATE_CONFIG
is set to yes
or true
the configuration file /etc/caddy/Caddyfile
is autogenerated using a simple template that lookup environment variables.
The templating supports defining multiple hostnames and multiple filters and proxies for each hostname. Example environment variables:
CADDY_GENERATE_CONFIG=yes
CADDY_ENTRY0_HOSTNAME=foo.bar.baz
CADDY_ENTRY0_TLS_MODE=self_signed
CADDY_ENTRY0_AUTH0_PATH=/
CADDY_ENTRY0_AUTH0_USERNAME=foo
CADDY_ENTRY0_AUTH0_PASSWORD=bar
CADDY_ENTRY0_PROXY0_PATH=/
CADDY_ENTRY0_PROXY0_DEST='http://localhost:8080'
CADDY_ENTRY0_FILTER0_PATH=/
CADDY_ENTRY0_FILTER0_CONTENT_TYPE='text/html.*'
CADDY_ENTRY0_FILTER0_SEARCH_PATTERN="=\" /"
CADDY_ENTRY0_FILTER0_REPLACEMENT="=\" /mesos/"
CADDY_ENTRY0_PROXY0_WEBSOCKET=yes
CADDY_ENTRY0_PROXY0_WITHOUT="/mesos"
CADDY_ENTRY0_PROXY0_TRANSPARENT="yes"
Which will create the following configuration::
foo.bar.baz {
filter rule {
path /
content_type text/html.*
search_pattern =" /
replacement =" /mesos/
}
basicauth / foo bar
tls self_signed
log stdout
errors stderr
proxy / http://localhost:8080 {
without /mesos
websocket
transparent
}
}
For other definitions use CADDY_ENTRY1
CADDY_ENTRY2
etc and for filters and proxies you can also increment the id to have multiple definitions.
Custom configuration can be inserted using CADDY_ENTRY0_CUSTOM0
and each line will be displayed in order at the bottom of the configuration of the hostname.
$ docker run -d -p 2015:2015 hbpmip/caddy:0.10.10-5
Point your browser to http://127.0.0.1:2015
.
Be aware! If you don't bind mount the location certificates are saved to, you may hit Let's Encrypt rate limits rending further certificate generation or renewal disallowed (for a fixed period)! See "Saving Certificates" below!
Save certificates on host machine to prevent regeneration every time container starts. Let's Encrypt has rate limit.
$ docker run -d \
-v $(pwd)/Caddyfile:/etc/Caddyfile \
-v $HOME/.caddy:/root/.caddy \
-p 80:80 -p 443:443 \
hbpmip/caddy:0.10.10-5
Here, /root/.caddy
is the location inside the container where caddy will save certificates.
Additionally, you can use an environment variable to define the exact location caddy should save generated certificates:
$ docker run -d \
-e "CADDYPATH=/etc/caddycerts" \
-v $HOME/.caddy:/etc/caddycerts \
-p 80:80 -p 443:443 \
hbpmip/caddy:0.10.10-5
Above, we utilize the CADDYPATH
environment variable to define a different location inside the container for
certificates to be stored. This is probably the safest option as it ensures any future docker image changes don't interfere with your ability to save certificates!
Caddy can serve sites from git repository using git plugin.
Replace github.com/abiosoft/webtest
with your repository.
$ printf "0.0.0.0\nroot src\ngit github.com/abiosoft/webtest" > Caddyfile
$ docker run -d -v $(pwd)/Caddyfile:/etc/Caddyfile -p 2015:2015 abiosoft/caddy
Point your browser to http://127.0.0.1:2015
.
You can build a docker image with custom plugins by specifying plugins
build arg as shown in the example below.
docker build --build-arg \
plugins=filemanager,git,linode \
github.com/abiosoft/caddy-docker.git
The image contains a default Caddyfile.
0.0.0.0
browse
fastcgi / 127.0.0.1:9000 php # php variant only
on startup php-fpm7 # php variant only
The last 2 lines are only present in the php variant.
Caddyfile: /etc/Caddyfile
Sites root: /srv
Replace /path/to/Caddyfile
and /path/to/sites/root
accordingly.
$ docker run -d \
-v /path/to/sites/root:/srv \
-v path/to/Caddyfile:/etc/Caddyfile \
-p 2015:2015 \
hbpmip/caddy
Note that this does not work on local environments.
Use a valid domain and add email to your Caddyfile to avoid prompt at runtime.
Replace mydomain.com
with your domain and user@host.com
with your email.
mydomain.com
tls user@host.com
You can change the the ports if ports 80 and 443 are not available on host. e.g. 81:80, 444:443
$ docker run -d \
-v $(pwd)/Caddyfile:/etc/Caddyfile \
-p 80:80 -p 443:443 \
hbpmip/caddy