Simple Development Proxy for productive full-stack development.
This is a Docker image for Caddy web server. This image runs with a base of Alpine-Linux making it extremely small, secure and fast.
Create an .env
file in the root directory of your project. Add environment-specific variables on new lines in the form of NAME=VALUE
. For example:
API_ROOT_1=https://your-api
API_ROOT_2=https://your-other-api
That's it.
Docker will pick up the keys and values you defined in your .env
file.
Should I commit my ".env" file?
No. We strongly recommend against committing your
.env
file to version control. It should only include environment-specific values such as database passwords or API keys.
Run the included start.sh
script to launch the Caddy container.
$ ./start.sh
Point your browser to http://localhost:3000
or http://localhost:4000
This image works with two defaults
- A default Caddyfile
- A default location inside the container for static files (optional):
/var/www/html
In order to use this image, we recommend running it with a volume connecting your static files to the root location of the docker file:
$ docker run -d -p 3000:3000 -p 4000:4000 -v $(pwd)/public:/var/www/html alpine-caddy
The server will be available at http://your.docker.machine.ip
The benefits of building an image with a overrideable Caddyfile are that you can include your own by including another volume.
For writing a custom Caddyfile please read this.
The image contains a default Caddyfile. It acts as a simple reverse proxy
localhost:3000 {
gzip
log stdout
errors stdout
cors
root /var/www/html
proxy /api {$API_ROOT_1} {
header_upstream Accept-Encoding {>Accept-Encoding}
}
}
localhost:4000 {
gzip
log stdout
errors stdout
cors
root /var/www/html
proxy /api {$API_ROOT_2} {
header_upstream Accept-Encoding {>Accept-Encoding}
}
}
It’s possible to use environment variables in your shell to populate values inside a Caddyfile:
API_ROOT_1
andAPI_ROOT_2
are substituted with values configured in the.env
file.
Alpine-Caddy has three locations where volumes can be linked to.
In order to serve static content, alpine-caddy needs to be able to access your static files from inside of the container. To do this, link the directory of your static files with /var/www/html inside of the container.
For docker-compose.yml files, under the volumes declaration, include:
- ./public:/var/www/html
or
$ docker run -v $(pwd)/public:/var/www/html
To upload a custom Caddyfile, link your Caddyfile to the directory /etc/Caddyfile in the container. For docker-compose.yml files, under the volumes declaration, include:
- ./Caddyfile:/etc/Caddyfile
or
$ docker run -v $(pwd)/Caddyfile:/etc/Caddyfile alpine-caddy