Caddyfile completely broken with mounts in Docker in Docker

1. The problem I’m having:

I created an issue in the github repo but was locked out of it. I’ve tried to recreate the problem without any real logic. It’s potentially a docker or linux permissions issue but I’ve had so much trouble with the Caddyfile itself in linux that I thought starting here was a good idea. I originally discovered the error within a github action, so I can add a minimum example of that to the repo as well if that was useful.ls

Original Issue:

Way to reproduce:

A significantly harder to follow/with more logic version of the issue can be found here, and is where the github action error messages come from for now:

2. Error messages and/or full log output:

wsl:

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/c98fe09064aae913ca993f3abd2c8fdf9674315eb4ae608f553688660e9d55d0" to rootfs at "/etc/caddy/Caddyfile": mount /run/desktop/mnt/host/wsl/docker-desktop-bind-mounts/Ubuntu/c98fe09064aae913ca993f3abd2c8fdf9674315eb4ae608f553688660e9d55d0:/etc/caddy/Caddyfile (via /proc/self/fd/14), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

github actions:

Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/__w/nvim_base/nvim_base/nvim_base/deploy-sourcegraph-docker/caddy/builtins/http.Caddyfile" to rootfs at "/etc/caddy/Caddyfile": mount /__w/nvim_base/nvim_base/nvim_base/deploy-sourcegraph-docker/caddy/builtins/http.Caddyfile:/etc/caddy/Caddyfile (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

3. Caddy version:

2.7-alpine
sha256:57942bf7e71d78bc866cbc6c45f0563dbbea73efedac5e731b4b2cffa75e45b4

4. How I installed and ran Caddy:

https://dl.cloudsmith.io/public/caddy/stable/deb/debian

a. System environment:

Ubuntu 22.04 Image in Github Ubuntu 22.04 Runner / WSL

b. Command:

https://github.com/david-engelmann/caddy_baddy

just run
docker compose -f docker-compose.yml up

c. Service/unit/compose file:

https://github.com/david-engelmann/caddy_baddy

The docker inside will be installed for you, it use docker compose, externally and internally

d. My complete Caddy config:

# Routes all plain http requests to sourcegraph-frontend - suitable for local testing.
#
# Caddyfile documentation: https://caddyserver.com/docs/caddyfile

:80

# Add the reverse proxies IPs (or IP CIDR ranges) to the trusted_proxies list.
# More information in https://caddyserver.com/docs/caddyfile/directives/reverse_proxy
reverse_proxy {
	to {$SRC_FRONTEND_ADDRESSES}
	trusted_proxies 0.0.0.0/0
}

If I’m totally barking up the wrong tree or the test logic is unsound, I apologize in advance.

This looks wrong. It doesn’t look like the left side of the : has http.Caddyfile as you suggest is your file.

I think your docker run command is incorrect. Make sure it properly maps to the correct file.

Essentially, this is a problem with Docker, not with Caddy. This is a problem before Caddy even runs, and in fact, before the Docker container itself even runs. It fails to run because the bind mount fails. It has nothing to do with the filename, nor the contents of the Caddyfile.

Hi Francis, thank you for responding! I’ve been banging my head against this for weeks now, still seems like a Docker in Docker issue. I created a GitHub discussion because it’s happening in GitHub actions and a docker community post as well - Running docker compose services with config files from Github Actions - General Discussions - Docker Community Forums. Still not sure how to make my config files present when launching from docker in docker. I thought it would be a big use case here so I was hoping someone would have some insight for me

I don’t understand what you’re trying to do.

Can’t you just use a docker-compose file like this?

@francislavoie That’s just a typical setup. I’m trying to run that setup from within a Docker container. The issue occurred when using docker-in-docker. the first docker container you launch the second docker container from isn’t the host and thus the files aren’t present when referencing the first docker container’s file path. I ended up needing a Dockerfile for the second docker container and having in the Dockerfile, a step to copy over my configs.

Basically, I switched the broken version

  caddy:
    container_name: caddy
    image: 'index.docker.io/caddy:2.7.3-alpine@sha256:f9824933254e3e43e0508670ee9bdcde704621017e95119a05317383b1878f4f'

With the working version

  caddy:
    container_name: caddy
    build:
      context: ../caddy
      dockerfile: Dockerfile.caddy

Here is the Dockerfile.caddy where my config is moved over

FROM caddy:2.7.3-alpine
COPY ./builtins/http.Caddyfile /etc/caddy/Caddyfile

I had an original github issue - Caddyfile unrecognizable from linux · Issue #5670 · caddyserver/caddy · GitHub - Would it be possible to link this community post and resolution to it. It’s been locked in Github

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