Bind Mount vs Docker Volume on Caddy

1. The problem I’m having:

Hi, I’m new to Caddy and Docker.
In almost everything I studied about Docker I read that it would be better to leave container volumes in production as Docker Volume instead of Bind Mount.

And then I noticed that in the Caddy documentation, when creating docker-compose.yml, two volumes are in Bind Mount.

Could you explain to me why it is recommended to place these volumes in Bind Mount instead of Volume Docker?
If they were placed on Docker Volume will there be any problems or difficulties, or will it be the same thing?


version: "3.9"

    image: caddy:<version>
    restart: unless-stopped
      - "80:80"
      - "443:443"
      - "443:443/udp"
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./site:/srv
      - caddy_data:/data
      - caddy_config:/config


A bind mount is the easiest way to mount a configuration file into the container. You typically want your Caddyfile to live on the host next to your compose.yml.

Also, the /srv one is optional, but it’s an example of how you could mount a website into the container to serve your own website contents (static site, or PHP, whatever). You don’t need it if you’re only using Caddy to proxy to other containers and whatnot.

If you use a volume, then it’s a lot harder to mount your own files inside. Volumes are best for when the container is generating data that you need to persist, but it doesn’t allow for mounting your own files inside the container (not easily anyway, it’s possible with docker compose cp and whatnot, but that’s awkward and not ideal).

Oh. I believe I understand.
Docker Volume = Files that I do not modify directly, like app settings that are modified within the application.
Bind Mount = Files that I modify directly.

Would it be this?

1 Like

Pretty much, yeah.

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