Can't start docker container

1. The problem I’m having:

Hey guys, I’m trying to move form NPM to caddy. I’m getting error when I try to start docker container using this docker-compose.yaml:

services:
  caddy:
    image: caddy:2.8.4
    container_name: caddy
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
      - 443:443/udp
    volumes:
      - /home/config/caddy/Caddyfile:/etc/caddy/Caddyfile
      - /home/config/caddy/site:/srv
      - /home/config/caddy/caddy_data:/data
      - /home/config/caddy/caddy_config:/config
volumes:
  caddy_data:
  caddy_config:

2. Error messages and/or full log output:

Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/home/config/caddy/Caddyfile" to rootfs at "/etc/caddy/Caddyfile": mount /home/config/caddy/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:

Trying to install 2.8.4

4. How I installed and ran Caddy:

Docker on Debian

b. Command:

sudo docker compose up -d

c. Service/unit/compose file:

I’m not sure what this is tbh

d. My complete Caddy config:

I don’t have it yet

5. Links to relevant resources:

I tried to follow this: Keep Caddy Running — Caddy Documentation

I have also tried non-modified yaml from this link and also some other guides. I have never experienced error like this, but I’m not Docker expert. Need some help please

Thanks in advance
R

Howdy @rambos, welcome to the Caddy community.

Have you checked the host path? What is at /home/config/caddy/Caddyfile? Is it a file? (It should be a file.)

Inside the container there is already a file at /etc/caddy/Caddyfile so if you try to mount nothing or a directory here, it’ll spit this error out.

1 Like

Thank you and sorry for late response. I did check that and docker compose up is creating a folder called Caddyfile. I have manually deleted the folder and created a file with the same name. Is this correct way or I’m missing something?

I tried to put some proxy hosts and now I’m getting different errors (DNS), but feels too early to post that here. I’ll keep trying myself, but would like to know have I done something wrong to get a folder instead of a file

Yep. With a bind mount you’re telling Docker to take a file or a folder from the host and put it in the container.

Naturally, the Caddy container expects a Caddyfile there, so you need to make a Caddyfile and put it there on the host so Docker can find that file and make it available inside the container, as you’ve configured it.

I imagine the reason it errored is because you had nothing on the host. Docker assumes you’ll want a folder and makes one for you. This immediately fails for the reason you’ve seen above.

1 Like

Thank you!

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