caddyserver / caddy-docker

Source for the official Caddy v2 Docker Image
https://hub.docker.com/_/caddy
Apache License 2.0
405 stars 74 forks source link

Docker Compose example does not work #300

Closed jolteondude closed 1 year ago

jolteondude commented 1 year ago

I apologize for the generic title, I am not sure how to properly describe my issue. I've followed the docker compose guide from https://hub.docker.com/_/caddy and prepared the docker-file below:

version: "3.7"

services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./site:/srv
      - caddy_data:/data
      - caddy_config:/config

volumes:
  caddy_data:
    external: true
  caddy_config:

It describes that I need to create my own data volume, so I proceed by creating one: docker volume create caddy_caddy_data

But as I run the command docker compose up -d, I get this error message below:

_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 "/home/username_here/docker/caddy/Caddyfile" to rootfs at "/etc/caddy/Caddyfile": mount /home/usernamehere/docker/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

Am I doing something wrong? I get the same error if I skip creating a data volume and remove external: true from the volumes section. The Caddyfile folder is created as soon as I run the docker compose command, as described in the error message. I don't know if it's the intended behavior, so I don't understand what's the issue here.

Thank you in advance for any help.

francislavoie commented 1 year ago

Make sure you create your Caddyfile next to docker-compose.yml before running it. It must be a file, not a directory.

jolteondude commented 1 year ago

Followed your instructions and it runs now. Thank you!