1. Caddy version (caddy version
):
latest
2. How I run Caddy:
Within a docker-compose.yml file along with an external environment file and an external Caddyfile.
a. System environment:
Ubuntu v20.04
b. Command:
docker-compose up -d
c. Service/unit/compose file:
version: '3.3'
services:
# Database
database:
image: mysql:latest
container_name: database
volumes:
- ./db:/var/lib/mysql
restart: always
env_file:
- .env
environment:
MYSQL_DATABASE: $WP_DB_NAME
command: '--default-authentication-plugin=mysql_native_password'
networks:
- blog-network
# WordPress
wordpress:
depends_on:
- database
image: wordpress:php7.4-fpm-alpine
container_name: wordpress
restart: always
user: "root:root"
env_file:
- .env
environment:
- WORDPRESS_DB_HOST=database:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=$WP_DB_NAME
volumes:
- ./php.ini:/usr/local/etc/php/conf.d/custom.ini
- ./wordpress:/var/www/html
networks:
- blog-network
# Webserver
caddy:
image: caddy:alpine
container_name: webserver
ports:
- 80:80
- 443:443
volumes:
- ./wordpress:/var/www/html
- ./caddy_data:/data
- ./caddy_config:/config
- ./Caddyfile:/etc/caddy/Caddyfile
networks:
- blog-network
networks:
blog-network:
driver: bridge
d. My complete Caddyfile or JSON config:
example.com {
root * /var/www/html
php_fastcgi wordpress:9000
file_server
}
Additionally I have an .env environment file to define required credentials:
MYSQL_ROOT_PASSWORD=<password-goes-here>
MYSQL_USER=<user-goes-here>
MYSQL_PASSWORD=<password-goes-here>
3. The problem I’m having:
I want to add one or more additional WordPress instances. Each instance is referenced by a subdomain, and I’d like Caddy to do the routing and SSL generation.
I successfully created a docker-compose.yml file to create many WordPress instances referenced by port, but I can’t figure out how to format the Caddyfile to have Caddy route the subdomains properly.
What’s confusing me is that in the docker-compose.yml file above, WordPress is defined without any reference to ports, yet the Caddyfile referenced port 9000. How is this determined, and more importantly, if I want to create additional reverse proxy entries in my Caddyfile, how do I do this?
4. Error messages and/or full log output:
None at this time, as I am still trying to figure out how to format the Caddyfile.
5. What I already tried:
I successfully created a docker-compose.yml file to create many WordPress instances referenced by port, but I can’t figure out how to format the Caddyfile to have Caddy route the subdomains properly.