mermaid-mode icon indicating copy to clipboard operation
mermaid-mode copied to clipboard

FYI: Configuration for running mmdc via mermaid-cli docker image

Open nickbp opened this issue 2 years ago • 3 comments

The following configuration will allow rendering mermaid charts without needing to install nodejs+mermaid-cli to the local OS. Instead it will execute mmdc via the mermaid-cli docker image. Figured it'd make sense to note this somewhere in case someone else found it useful:

(setq mermaid-mmdc-location "docker")
(setq mermaid-flags "run -u 1000 -v /tmp:/tmp ghcr.io/mermaid-js/mermaid-cli/mermaid-cli:9.1.6")

Some explanation of the docker run arguments:

  • -u 1000 ensures that the resulting output png file has a matching UID to the current user, avoiding permissions issues when deleting or overwriting the png. The 1000 is my UID on my machine. There might be a way to figure out the UID directly in emacs.
  • -v /tmp:/tmp mounts the host /tmp to /tmp inside the container. This ensures that mmdc inside the container will be reading/writing to the host /tmp when rendering.
  • 9.1.6: Latest stable version as of this writing. Can check available tags here

nickbp avatar Sep 28 '22 15:09 nickbp

Thank you for sharing! I will add this to the readme.

Which docker image do you use? https://hub.docker.com/r/matthewfeickert/mermaid-cli ?

abrochard avatar Sep 29 '22 01:09 abrochard

I've been using the "official" one on the GitHub container registry, ghcr.io/mermaid-js/mermaid-cli/mermaid-cli:9.1.6 in the above example.

nickbp avatar Sep 29 '22 16:09 nickbp

One catch I've just found is that the "current buffer" command works but the "current file" command doesn't work. I assume because the current file isn't necessarily visible to the docker container. The workaround would be to stick to the "current buffer" command where it writes the input to /tmp/current-buffer.mmd

nickbp avatar Sep 29 '22 16:09 nickbp