1. Caddy version (caddy version
):
caddy:2.2.1-alpine
2. How I run Caddy:
with docker compose (see below):
a. System environment:
Using Docker (compose)
b. Command:
docker-compose -f docker-compose-caddy-angular.yml up -d
c. Service/unit/compose file:
version: "3.7"
services:
duckdb:
image: mysql:latest
container_name: duckdb
volumes:
- duck:/var/lib/mysql
ports:
- 3306:3306
environment:
MYSQL_ROOT_HOST: '%'
MYSQL_ROOT_USER: ****
MYSQL_ROOT_PASSWORD: *****
MYSQL_DATABASE: duckdb
spring-app:
build:
context: ./
dockerfile: Dockerfile
ports:
- 8080:8080
depends_on:
- duckdb
environment:
- SPRING_PROFILES_ACTIVE=prod
angular-ui:
build: ../chuck
container_name: chuck
ports:
- 4200:4200
# Run the caddy server
caddy:
image: caddy/caddy:2.2.1-alpine
container_name: caddy-service
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- $PWD/Caddyfile:/etc/caddy/Caddyfile
- $PWD/site:/srv
- caddy_data:/data
- caddy_config:/config
volumes:
caddy_data:
caddy_config:
duck:
d. My complete Caddyfile or JSON config:
kvasen.xyz {
reverse_proxy spring-app:8080 {
header_down Strict-Transport-Security max-age=31536000;
}
encode zstd gzip
file_server
root * /app/dist/chuck
rewrite * /app/dist/chuck/index.html
}
3. The problem I’m having:
Originally I tried Caddy because I was having too much trouble configuring Nginx with Let’s encrypt. It worked great when I tried it only with the Spring Api, my Caddyfile being:
kvasen.xyz {
reverse_proxy spring-app:8080 {
header_down Strict-Transport-Security max-age=31536000;
}
}
I correctly get the exposed endpoints and their data.
Next step is adding a client (Angular). But I am missing something somewhere and there aren’t many examples with Docker. My Dockerfile for Angular is:
FROM node:lts-alpine as node
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build --configuration=prod
#stage 2
FROM caddy/caddy:2.2.1-alpine
COPY --from=node /app/dist/chuck /srv
# old stage 2 with NGINX
#FROM nginx:stable-alpine
#COPY --from=node /app/dist/chuck /usr/share/nginx/html
#EXPOSE 80
#EXPOSE 443
#CMD ["nginx", "-g", "daemon off;"]
4. Error messages and/or full log output:
5. What I already tried:
Tried different ways of “reaching” the angular code, but before adding:
rewrite * /app/dist/chuck/index.html
I always got the api responses, and after adding the rewrite I get 403 everywhere.
Probably a working example of an Angular + any Backend in a Docker environment would be enough as an answer…