SOLVED: Please help. Trying to use dockerls as a podman container

EDIT: Solved. I found this: LSP: Allow configuration to control processId · Issue #14504 · neovim/neovim · GitHub Used --pid=host as part of the cmd and the server runs. :smiley:

I have been trying to use GitHub - rcjsuen/dockerfile-language-server-nodejs: A language server for Dockerfiles powered by Node.js, TypeScript, and VSCode technologies. as a podman container, but without success. I HAVE been able to get the sumneko_lua lanugage server working in podman. I have attempted these both on Manjaro & Ubuntu 20.04 WSL2

These are the images I have attempted to use:

rcjsuen/docker-langserver on Docker Hub (0.4.1)

The Dockerfile rcjsuen used for the 0.4.1 image:

FROM node:alpine
COPY lib /docker-langserver/lib
COPY bin /docker-langserver/bin
COPY package.json /docker-langserver/package.json
WORKDIR /docker-langserver/
RUN npm install --production && \
    chmod +x /docker-langserver/bin/docker-langserver
ENTRYPOINT [ "/docker-langserver/bin/docker-langserver" ]

My lua config in vimrc:

" {{{ docker language-server
lua << EOF
require'lspconfig'.dockerls.setup{
    cmd = {
        "podman",
        "run",
        "--interactive",
        "--rm",
        "--volume",
        vim.loop.cwd() .. ':/usr/src',
        "rcjsuen/docker-langserver",
        "--stdio",
    }
}
EOF
" }}}

Opening a Dockerfile results in Client 1 quit with exit code 1 and signal 0 and also a warning in ~/.cache/nvim/lsp.log:

[WARN][2021-10-22 13:40:56] ...lsp/handlers.lua:108     "The language server dockerls triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"

lspcontainers/docker-language-server on Docker Hub (0.4.1)

The Dockerfile used in the lspcontainers image:

FROM alpine:3.13.5

RUN apk add --no-cache \
  nodejs \
  npm

ARG VERSION

RUN npm install -g \
  dockerfile-language-server-nodejs@${VERSION}

CMD [ "/usr/bin/docker-langserver", "--stdio" ]

My lua config in vimrc:

" {{{ docker language-server
lua << EOF
require'lspconfig'.dockerls.setup{
    cmd = {
        "podman",
        "run",
        "--interactive",
        "--rm",
        "--volume",
        vim.loop.cwd() .. ':/usr/src',
        "lspcontainers/docker-language-server",
    }
}
EOF
" }}}

Opening a Dockerfile results in Client 1 quit with exit code 1 and signal 0 and also a warning in ~/.cache/nvim/lsp.log:

[WARN][2021-10-22 14:00:26] ...lsp/handlers.lua:108     "The language server dockerls triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"

Dockerfile I built locally:

FROM alpine:3.13.5

RUN apk add --no-cache \
  nodejs \
  npm

RUN npm install -g \
  dockerfile-language-server-nodejs@0.7.2

CMD [ "/usr/bin/docker-langserver", "--stdio" ]

My lua config in vimrc:

" {{{ docker language-server
lua << EOF
require'lspconfig'.dockerls.setup{
    cmd = {
        "podman",
        "run",
        "--interactive",
        "--rm",
        "--volume",
        vim.loop.cwd() .. ':/usr/src',
        "localhost/dockerls",
    }
}
EOF
" }}}

Opening a Dockerfile results in Client 1 quit with exit code 1 and signal 0 and also a warning in ~/.cache/nvim/lsp.log:

[WARN][2021-10-22 14:04:19] ...lsp/handlers.lua:108     "The language server dockerls triggers a registerCapability handler despite dynamicRegistration set to false. Report upstream, this warning is harmless"

If I try any using --tty option I see an error in ~/.cache/nvim/lsp.log:

[ERROR][2021-10-22 14:07:39] .../vim/lsp/rpc.lua:462    "rpc"   "podman"        "stderr"        'time="2021-10-22T14:07:39-04:00" level=warning msg="The input device is not a TTY. The --tty and --interactive flags might not work properly"\n'

I have also tried using --attach stdin --attach stdout w/o success.

Neovim :version

:version
NVIM v0.5.1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion
 -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR
_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim
/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compiled by runner@fv-az87-829

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/home/runner/work/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info

Neovim :checkhealth

health#lspconfig#check¬                                                                                                
========================================================================¬                                              
## Checking language server protocol configuration¬                                                                    
  - INFO: dockerls: configuration checked.¬                                                                            
¬                                                                                                                      
health#nvim#check¬                                                                                                     
========================================================================¬                                              
## Configuration¬                                                                                                      
  - OK: no issues found¬                                                                                               
¬                                                                                                                      
## Performance¬                                                                                                        
  - OK: Build type: RelWithDebInfo¬                                                                                    
¬                                                                                                                      
## Remote Plugins¬                                                                                                     
  - OK: Up to date¬                                                                                                    
¬                                                                                                                      
## terminal¬                                                                                                           
  - INFO: key_backspace (kbs) terminfo entry: key_backspace=\177¬                                                      
  - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~¬                                                                 
¬                                                                                                                      
health#provider#check¬                                                                                                 
========================================================================¬                                              
## Clipboard (optional)¬                                                                                               
  - WARNING: No clipboard tool found. Clipboard registers (`"+` and `"*`) will not work.¬                              
    - ADVICE:¬                                                                                                         
      - :help clipboard¬                                                                                               
¬                                                                                                                      
## Python 2 provider (optional)¬                                                                                       
  - WARNING: No Python executable found that can `import neovim`. Using the first available executable for diagnostics.
  - ERROR: Python provider error:¬                                                                                     
    - ADVICE:¬                                                                                                         
      - provider/pythonx: Could not load Python 2:¬                                                                    
          python2 not found in search path or not executable.¬                                                         
          python2.7 not found in search path or not executable.¬                                                       
          python2.6 not found in search path or not executable.¬                                                       
          python not found in search path or not executable.¬                                                          
  - INFO: Executable: Not found¬                                                                                       
¬                                                                                                                      
## Python 3 provider (optional)¬                                                                                       
  - INFO: `g:python3_host_prog` is not set.  Searching for python3 in the environment.¬                                
  - INFO: Multiple python3 executables found.  Set `g:python3_host_prog` to avoid surprises.¬                          
  - INFO: Executable: /usr/bin/python3¬                                                                                
  - INFO: Other python executable: /bin/python3¬                                                                       
  - INFO: Python version: 3.8.10¬                                                                                      
  - INFO: pynvim version: 0.4.1 (outdated; from /usr/lib/python3/dist-packages/neovim)¬                                
  - WARNING: Latest pynvim is NOT installed: 0.4.3¬                                                                    
¬                                                                                                                      
## Python virtualenv¬                                                                                                  
  - OK: no $VIRTUAL_ENV¬                                                                                               
¬                                                                                                                      
## Ruby provider (optional)¬                                                       
  - INFO: Ruby: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]¬  
  - WARNING: `neovim-ruby-host` not found.¬                                        
    - ADVICE:¬                                                                     
      - Run `gem install neovim` to ensure the neovim RubyGem is installed.¬       
      - Run `gem environment` to ensure the gem bin directory is in $PATH.¬        
      - If you are using rvm/rbenv/chruby, try "rehashing".¬                       
      - See :help g:ruby_host_prog for non-standard gem installations.¬            
¬                                                                                  
## Node.js provider (optional)¬                                                    
  - WARNING: `node` and `npm` (or `yarn`) must be in $PATH.¬                       
    - ADVICE:¬                                                                     
      - Install Node.js and verify that `node` and `npm` (or `yarn`) commands work.
¬                                                                                  
## Perl provider (optional)¬                                                       
  - ERROR: perl provider error:¬                                                   
    - ADVICE:¬                                                                     
      - "Neovim::Ext" cpan module is not installed¬                                
¬                                                                                  
health#treesitter#check¬                                                           
========================================================================¬          
## Checking treesitter configuration¬                                              
  - INFO: Runtime ABI version : 13¬                                                
  - OK: Loaded parser for c: ABI version 13¬                                       

Might be good to update/clean up Running language servers in containers · neovim/nvim-lspconfig Wiki · GitHub

Happy to discuss/provide commentary, it’s not something I use so I probably won’t write the documentation.

There’s also distant.nvim which somewhat covers this usecase (if you’re editing a file that lives in the container as well).

The main issue is sharing the host pid namespace, as you already discovered, and also ensuring that the URIs match inside and outside the container (usually enough to bind mount $HOME into the container at $HOME). The other tricky party is for some servers (like clangd), you need to match libraries/what’s stored in compile_commands.json inside and outside the container.

1 Like

How does this look?

microsoft/vscode-languageserver-node based servers

The vscode-languageserver-node based server expects a client to create it. The server expects the client to supply a process id (the process id of the client). When the server cannot detect the process id, it assumes the client has exited and that it should exit. Since containers do not share process ids with the host this results in the server exiting immediately. See here (will add link on Wiki edit)

A way to handle this is using before_init and overriding initialize_params.process_id with a NIL (null) value as described here

A less ideal way to deal with this is to have the host and container share process ids via the docker/podman run argument --pid=host as mentioned here. Do note this is considered an insecure practice by both Docker and Podman. man docker-run or man podman-run and /--pid= for more info.

Seems good to me! The whole wiki entry need some streamlining though

1 Like