Caddy container setup issue

Hi, quick question, I used caddy before with my local setup (not inside docker) and it worked fine!
Now i am trying to run it via docker but i am getting this error:
GET http://localhost:8888/ui/app NOT FOUND

It seems like it cant find it? Going to / or /hello works correctly and responds correctly. So it seems like an issue in finding the root directory?
I bashed into my container and my frontend files are definitely located at




:80 {
	handle_path /ui/app* {
	    root * /srv
        try_files {path} /index.html

	handle {
	    respond "not found" 404

	handle / {
	    respond "index" 200

	handle /hello {
	    respond "hello" 200

My docker file:

FROM node:13.12.0-alpine as build
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm ci --silent
RUN npm install react-scripts@3.4.1 -g --silent
COPY . ./
RUN npm run build

FROM caddy:2.1.1-alpine
COPY Caddyfile /etc/caddy/Caddyfile
COPY build /srv
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]

I was hoping for a quick and simple fix, because this setup works when i run it locally outside of docker.

EDIT: I made it work using nginx with this configuration:

server {
    listen 80;
    location =  /ui/app {
            root /srv;
            try_files /index.html =404;

    location ~ ^/ui/app(.*) {
            root /srv;
            try_files $1 $1/ /index.html =404;

Hmm, I don’t see anything wrong with that. You are binding port 8888 on the host to 80 on the Caddy container, right?

To debug further, add log to your site block (enables access logs), add the debug global option to the top of your Caddyfile like this:


And then check the logs with docker logs caddy (or whatever you named the container). Try making the request with curl -v to see the whole response you got.

Thank you for the quick response. For some reason, caddy just doesn’t want to work for me at all inside docker. I even created a very simple Caddyfile:

handle /hello {
    respond "hello" 200

And it responded with “not found”
It seemed like it was using the old configuration which had this handler:

	handle {
	    respond "not found" 404

I then made sure to restart caddy, i even bashed into the container and looked at the caddy configuration file, then i even ran caddy adapt with the config file, still same result of it showing the not found message.

And that is where I just gave up, I couldn’t even make the hello world handler work for some reason.

I switched to traefik and it seemes to work great for me with docker and docker compose.

I have a feeling the problem was in your Dockerfile. You’re trying to do a multi-stage build, right? You did COPY build /srv, but I think you actually need to do COPY --from=build /app/build /srv or something like that (not sure what dir your npm build outputs to, so you’ll need to verify).

If the files aren’t actually in /srv then Caddy’s file_server will serve 404s.

This topic was automatically closed after 30 days. New replies are no longer allowed.