Search code examples
dockeremacs

Emacs workflow with development containers


New to Emacs and recently been trying to get used to it. loving it so far!

One thing I cannot seem to figure out by myself nor find any proper examples of how to figure out to following workflow:

Since I work on multiple projects with different languages and like to keep my work and private projects separated as much as possible in my OS, ive been working with development containers using docker and VScode for the past years.

This allowed me to keep both my project dependencies and the development tools in one container, where i just attached my VScode instance to a project and used extensions such as Language servers / linting / debugging from within that container.

Currently I can open my projects in emacs as the code is local and mounted to the containers, but im looking for a way to either:

  • Allow my local emacs to use the language/linting/debugging services installed in the container.
  • Install emacs in the dev containers and mount my configs to keep this synchronized.
  • Or better alternatives?

Most valuable would be to get language servers working again.

In case it matters, i'm working in DOOM Emacs on Arch. Mostly Python, PHP and NodeJS projects.


Solution

  • ... use the language/linting/debugging services installed in the container

    By design this is difficult to do with Docker: by design the host system can't directly access files or binaries installed in a container. Without a lot of tricks around bind mounts and user IDs and paths and permissions it's very difficult to run a program in a container in a way that looks like it's on the host system. A couple of tools have those tricks built in, but it's not at all universal. (Jenkins for example generates about 5 lines' worth of docker run command options if you ask it to run a step inside a container.)

    My Emacs experience has generally been much better using a host-based per-language version manager and per-project packaging tool (a per-project node_modules directory, rbenv plus Ruby gem sets, pipenv for Python programs, ...).

    In short: Emacs can't use language servers, language interpreters, or other tools from Docker images instead of the host system (without writing a lot of Lisp (and if you do consider publishing it to MELPA (and also to GitHub))).

    Most valuable would be to get language servers working again.

    M-x lsp-install-server will download one of the language servers lsp-mode knows about and save it in your $HOME/.emacs directory. If you activate lsp-mode and it doesn't already have a language server for the current major mode, it will offer to download it for you. There's not much to "get working" usually.