Skip to content

Launching python script inside docker container fails with "No such container" error #478

Closed
@TamaMcGlinn

Description

@TamaMcGlinn

DO NOT DELETE THIS TEMPLATE. IF YOU DELETE THIS TEMPLATE AND DO NOT COMPLETE IT, YOUR ISSUE WILL BE CLOSED.

Describe the bug

Provide A clear and concise description of what the bug is.

In trying to follow [this Docker example] from Vimspector's configuration documentation page, and after fixing a few obvious mistakes in that configuration, launch still does not work even for a trivial python script inside of Docker, exiting with status 1 and message: "Error: no such container: [whatever you entered for container]"

Minimal reproduciton

Please answer the following questions

  • Does your issue reproduce using vim --clean -Nu /path/to/vimspector/support/minimal_vimrc ? For nvim, yes. For vim, it gives this exact error instead. This is probably unrelated and I don't care about that since I use Neovim myself.
  • If you are using Neovim, does your issue reproduce using Vim? No, but probably only because the aforementioned error occurs first.

List of steps to reproduce:

  1. Run nvim ---clean Nu /path/to/vimspector/support/minimal_vimrc
  2. Open script.py inside this example python in docker project
  3. :call vimspector#Launch()
  4. Choose 2: remote-launch
  5. Enter value for RemoteRoot: /usr/src/app
  6. Enter value for args:
  7. Enter value for port: 3748
  8. Enter value for container: anything
  9. Enter value for filename: script.py

Note that container and port can be anything you choose, as I'm expecting launch to launch a new container, so long as the connecting part executes in the same container that was spawned everything should work fine.

Use the following Vimspector config file:

I copied the vimspector config from the documentation example, just adding comma's where necessary, on lines 26 and 65.

{
  "adapters": {
    "python-remote": {
      "port": "${port}",
      "launch": {
        "remote": {
          "container": "${container}", // Docker container id or name to exec into to.

          // Command to launch the debugee and attach the debugger; 
          // %CMD% replaced with the remote-cmdLine configured in the launch
          // configuration. (mandatory)
          "runCommand": [
            "python", "-m", "debugpy",
            "--listen", "0.0.0.0:${port}",
            "--wait-for-client",
            "%CMD%"
          ]
          
          // Optional alternative to runCommand (if you need to run multiple
          // commands)
          // "runCommands":  [
          //   [ /* first command */ ],
          //   [ /* second command */ ]
          // ]

        },
        
        // optional delay to wait after running runCommand(s). This is often
        // needed because of the way docker handles TCP
        "delay": "1000m" // format as per :help sleep
      },
      "attach": {
        "remote": {
          "container": "${container}", // Docker container id or name to exec into.
          // Command to get the PID of the process to attach  (mandatory)
          // This command gets appended to "docker exec ${container}"
          "pidCommand": [
            //
            // Remember taht you can use ${var} to ask for input. I use this to
            // call a custom command to returm the PID for a named service, so
            // here's an examle:
            //
            "sh", "-c", "pgrep", "-f", "${filename}"
          ],

          // Command to attach the debugger; %PID% replaced with output of
          // pidCommand above (mandatory)
          "attachCommand": [
            "sh", "-c", "python", "-m", "debugpy", "--listen", "0.0.0.0:${port}",
            "--pid", "%PID%"
          ]
          
          // Optional alternative to attachCommand (if you need to run multiple
          // commands)
          // "attachCommands":  [
          //   [ /* first command */ ],
          //   [ /* second command */ ]
          // ],

          // Optional.... useful with buggy gdbservers to kill -TRAP %PID%
          // "initCompleteCommand": [
          //   /* optional command to run after initialized */
          // ]

        },

        // optional delay to wait after running runCommand(s). This is often
        // needed because of the way docker handles TCP, or if you're using some
        // wrapper (e.g. to start the JVM)
        "delay": "1000m" // format as per :help sleep
      }
    }
  },
  "configurations": {
    "remote-launch": {
      "adapter": "python-remote",

      "remote-request": "launch",
      "remote-cmdLine": [
        "${RemoteRoot}/${fileBasename}", "*${args}"
      ],

      "configuration": {
        "request": "attach",
        "pathMappings": [
          {
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "${RemoteRoot}"
          }
        ]
      }
    },
    "remote-attach": {
      "variables": {
        // Just an example of how to specify a variable manually rather than
        // vimspector asking for input from the user
        "FileName": "${fileName}"
      },

      "adapter": "python-remote",
      "remote-request": "attach",

      "configuration": {
        "request": "attach",
        "pathMappings": [
          {
            "localRoot": "${workspaceRoot}",
            "remoteRoot": "${RemoteRoot}"
          }
        ]
      }
    }
  }
}

Expected behaviour

Provide A clear and concise description of what you expected to happen.

I expected the launch command to start debugpy's execution of script.py within a newly spun-up docker container, and then for vimspector to connect to that process so that debugging can commence.

Actual behaviour

What actually happened, including output, log files etc.

Vimspector tab opens with all the default windows, and a message is shown in the middle of the screen "Initializing debug adapter". After 10 attempts are made to connect, it stops and the error: "No such container: anything" is shown in the output window.

Please include:

  • Vimspector log (~/.vimspector.log)
2021-10-14 16:21:17,233 - INFO - **** INITIALISING NEW VIMSPECTOR SESSION ****
2021-10-14 16:21:17,233 - INFO - API is: neo
2021-10-14 16:21:17,233 - INFO - VIMSPECTOR_HOME = /home/s1000586/.vim/plugged/vimspector
2021-10-14 16:21:17,235 - INFO - gadgetDir = /home/s1000586/.vim/plugged/vimspector/gadgets/linux
2021-10-14 16:21:17,237 - INFO - User requested start debug session with {}
2021-10-14 16:21:17,238 - DEBUG - Reading configurations from: None
2021-10-14 16:21:17,238 - DEBUG - Reading configurations from: /home/s1000586/code/python_in_docker_example/.vimspector.json
2021-10-14 16:21:17,249 - DEBUG - Reading gadget config: /home/s1000586/.vim/plugged/vimspector/gadgets/linux/.gadgets.json
2021-10-14 16:21:17,250 - DEBUG - Reading gadget config: None
2021-10-14 16:21:21,527 - DEBUG - Value for RemoteRoot not set in ${RemoteRoot}/${fileBasename} (from ${RemoteRoot}/${fileBasename}): set to /usr/src/app
2021-10-14 16:21:22,320 - DEBUG - Value for args not set in ${args} (from ${args}): set to 
2021-10-14 16:21:24,632 - DEBUG - Value for port not set in ${port} (from ${port}): set to 3748
2021-10-14 16:21:26,952 - DEBUG - Value for container not set in ${container} (from ${container}): set to something
2021-10-14 16:21:29,727 - DEBUG - Value for filename not set in ${filename} (from ${filename}): set to script.py
2021-10-14 16:21:29,727 - INFO - Configuration: {"adapter": "python-remote", "remote-request": "launch", "remote-cmdLine": ["/usr/src/app/script.py"], "configuration": {"request": "attach", "pathMappings": [{"localRoot": "/home/s1000586/code/python_in_docker_example", "remoteRoot": "/usr/src/app"}]}}
2021-10-14 16:21:29,728 - INFO - Adapter: {"port": "3748", "launch": {"remote": {"container": "something", "runCommand": ["python", "-m", "debugpy", "--listen", "0.0.0.0:3748", "--wait-for-client", "%CMD%"]}, "delay": "1000m"}, "attach": {"remote": {"container": "something", "pidCommand": ["sh", "-c", "pgrep", "-f", "script.py"], "attachCommand": ["sh", "-c", "python", "-m", "debugpy", "--listen", "0.0.0.0:3748", "--pid", "%PID%"]}, "delay": "1000m"}}
2021-10-14 16:21:29,729 - DEBUG - min_width/height: 149/50, actual: 239/63 - result: horizontal
2021-10-14 16:21:29,771 - DEBUG - LAUNCH!
2021-10-14 16:21:29,773 - DEBUG - Running remote app: ['docker', 'exec', 'something', 'python', '-m', 'debugpy', '--listen', '0.0.0.0:3748', '--wait-for-client', '/usr/src/app/script.py']
2021-10-14 16:21:29,780 - INFO - User Msg: Waiting ( 1000m )...
2021-10-14 16:21:30,796 - INFO - Starting debug adapter with: {"port": "3748", "launch": {"remote": {"container": "something", "runCommand": ["python", "-m", "debugpy", "--listen", "0.0.0.0:3748", "--wait-for-client", "%CMD%"]}, "delay": "1000m"}, "attach": {"remote": {"container": "something", "pidCommand": ["sh", "-c", "pgrep", "-f", "script.py"], "attachCommand": ["sh", "-c", "python", "-m", "debugpy", "--listen", "0.0.0.0:3748", "--pid", "%PID%"]}, "delay": "1000m"}}
2021-10-14 16:21:30,796 - DEBUG - Connection Type: neochannel
2021-10-14 16:21:40,810 - INFO - Debug Adapter Started
2021-10-14 16:21:40,810 - DEBUG - Sending Message: {"command": "initialize", "arguments": {"adapterID": "adapter", "clientID": "vimspector", "clientName": "vimspector", "linesStartAt1": true, "columnsStartAt1": true, "locale": "en_GB", "pathFormat": "path", "supportsVariableType": true, "supportsVariablePaging": false, "supportsRunInTerminalRequest": true}, "seq": 0, "type": "request"}
2021-10-14 16:21:55,812 - DEBUG - Timeout: Aborting request {'command': 'initialize', 'arguments': {'adapterID': 'adapter', 'clientID': 'vimspector', 'clientName': 'vimspector', 'linesStartAt1': True, 'columnsStartAt1': True, 'locale': 'en_GB', 'pathFormat': 'path', 'supportsVariableType': True, 'supportsVariablePaging': False, 'supportsRunInTerminalRequest': True}, 'seq': 0, 'type': 'request'}
2021-10-14 16:21:55,812 - INFO - User Msg: Request for initialize aborted: Timeout
  • Output from any or all UI diagnostic tabs (Server, etc.)
Error: No such container: anything

[Process exited 1]

Environemnt

NOTE: NeoVim is supported only on a best-effort basis. Please check the README
for limitations of neovim. Don't be offended if I ask you to reproduce issues in
Vim.

NOTE: Windows support is experimental and best-effort only. If you find an
issue related to Windows or windows-isms, consider sending a PR or
discussing on Gitter rather than raising an issue.

  • Version of Vimspector: (e.g. output of git rev-parse HEAD if cloned or the
    name of the tarball used to install otherwise)
~/.vim/plugged/vimspector$ g rev-parse HEAD
57ce0992803fcf22c0557550fff45e3fe869f707
  • Output of :VimspectorDebugInfo
Vimspector Debug Info
--------------------------------------------------------------------------------
ConnectionType: neochannel
Adapter: 
--------------------------------------------------------------------------------
{
  "port": "3748",
  "launch": {
    "remote": {
      "container": "something",
      "runCommand": [
        "python",
        "-m",
        "debugpy",
        "--listen",
        "0.0.0.0:3748",
        "--wait-for-client",
        "%CMD%"
      ]
    },
    "delay": "1000m"
  },
  "attach": {
    "remote": {
      "container": "something",
      "pidCommand": [
        "sh",
        "-c",
        "pgrep",
        "-f",
        "script.py"
      ],
      "attachCommand": [
        "sh",
        "-c",
        "python",
        "-m",
        "debugpy",
        "--listen",
        "0.0.0.0:3748",
        "--pid",
        "%PID%"
      ]
    },
    "delay": "1000m"
  },
  "env": {},
  "cwd": "/home/s1000586/code/python_in_docker_example"
}
--------------------------------------------------------------------------------
Configuration: 
--------------------------------------------------------------------------------
{
  "adapter": "python-remote",
  "remote-request": "launch",
  "remote-cmdLine": [
    "/usr/src/app/script.py"
  ],
  "configuration": {
    "request": "attach",
    "pathMappings": [
      {
        "localRoot": "/home/s1000586/code/python_in_docker_example",
        "remoteRoot": "/usr/src/app"
      }
    ]
  }
}
--------------------------------------------------------------------------------
API Prefix: neo
Launch/Init: False / False
Workspace Root: /home/s1000586/code/python_in_docker_example
Launch Config: 
--------------------------------------------------------------------------------
{
  "request": "attach",
  "pathMappings": [
    {
      "localRoot": "/home/s1000586/code/python_in_docker_example",
      "remoteRoot": "/usr/src/app"
    }
  ],
  "name": "test"
}
--------------------------------------------------------------------------------
Server Capabilities: 
--------------------------------------------------------------------------------
{}
--------------------------------------------------------------------------------
  • Output of vim --version or nvim --version
$ nvim --version
NVIM v0.6.0-dev+107-g3d1835967
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 -Wimp
licit-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/neo
vim/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-az32-871

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
  • Output of which vim or which nvim:
$ which nvim
/usr/bin/nvim
  • Output of :py3 print( __import__( 'sys' ).version ):
3.8.10 (default, Sep 28 2021, 16:10:42
[GCC 9.3.0]
  • Output of :py3 import vim:
  • Output of :py3 import vimspector:

Note the previous two are empty, they return nothing at all.

  • For neovim: output of :checkhealth
health#completion_nvim#check
========================================================================
## general
  - OK: neovim version is supported

## completion source
  - OK: all completion sources are valid

## snippet source
  - OK: You are using UltiSnips as your snippet source

health#lspconfig#check
========================================================================
## Checking language server protocol configuration
  - INFO: bashls: configuration checked.
  - INFO: vimls: configuration checked.
  - INFO: pylsp: configuration checked.
  - INFO: rust_analyzer: configuration checked.
  - INFO: als: configuration checked.
  - INFO: clangd: configuration checked.

health#nvim_treesitter#check
========================================================================
## Installation
  - OK: `tree-sitter` found  0.20.0 (e85a279cf29da1b08648e27214dda20a841e57c8) (parser generator, only needed for :TSInstallFromGrammar)
  - OK: `node` found v10.19.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - python         ✓ ✓ ✓ ✓ ✓ 
  - c              ✓ ✓ ✓ ✓ ✓ 

 Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

health#gitmessenger#check
========================================================================
  - OK: +job is available to execute Git command
  - OK: Git command `git` is available: git version 2.25.1
  - OK: Floating window is available for popup window

health#floaterm#check
========================================================================
## common
  - INFO: Platform: linux
  - INFO: Nvim: NVIM v0.6.0-dev+107-g3d1835967
  - INFO: Plugin: 20618a6


## terminal
  - OK: Terminal emulator is available

## floating
  - OK: Floating window is available

health#nvim_treesitter#check
========================================================================
## Installation
  - OK: `tree-sitter` found  0.20.0 (e85a279cf29da1b08648e27214dda20a841e57c8) (parser generator, only needed for :TSInstallFromGrammar)
  - OK: `node` found v10.19.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - python         ✓ ✓ ✓ ✓ ✓ 
  - c              ✓ ✓ ✓ ✓ ✓ 

 Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

health#lspconfig#check
========================================================================
## Checking language server protocol configuration
  - INFO: bashls: configuration checked.
  - INFO: vimls: configuration checked.
  - INFO: pylsp: configuration checked.
  - INFO: rust_analyzer: configuration checked.
  - INFO: als: configuration checked.
  - INFO: clangd: configuration checked.

health#compe#check
========================================================================
## compe:snippet
  - OK: snippet engine detected.

## compe:mapping
  - INFO: `compe#complete` is not mapped
  - INFO: `compe#confirm` is not mapped
  - INFO: `compe#close` is not mapped
  - INFO: `compe#scroll` is not mapped

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~
  - INFO: $SSH_TTY='/dev/pts/1'

health#provider#check
========================================================================
## Clipboard (optional)
  - OK: Clipboard tool found: xclip

## Python 2 provider (optional)
  - INFO: `g:python_host_prog` is not set.  Searching for python2 in the environment.
  - INFO: Multiple python2 executables found.  Set `g:python_host_prog` to avoid surprises.
  - INFO: Executable: /usr/bin/python2
  - INFO: Other python executable: /bin/python2
  - INFO: Python version: 2.7.18
  - INFO: pynvim version: 0.4.3
  - OK: Latest pynvim is installed.

## Python 3 provider (optional)
  - INFO: Using: g:python3_host_prog = "/usr/bin/python3"
  - INFO: Executable: /usr/bin/python3
  - INFO: Python version: 3.8.10
  - INFO: pynvim version: 0.4.3
  - OK: Latest pynvim is installed.

## Python virtualenv
  - OK: no $VIRTUAL_ENV

## Ruby provider (optional)
  - INFO: Ruby: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
  - INFO: Host: /usr/local/bin/neovim-ruby-host
  - WARNING: Gem "neovim" is out-of-date. Installed: 0.8.1, latest: 0.9.0
    - ADVICE:
      - Run in shell: gem update neovim

## Node.js provider (optional)
  - INFO: Node.js: v10.19.0
  - INFO: Nvim node.js host: /home/s1000586/.config/yarn/global//node_modules/neovim/bin/cli.js
  - OK: Latest "neovim" npm/yarn package is installed: 4.10.0

## 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
  - OK: Loaded parser for python: ABI version 13
  - OK: Loaded parser for c: ABI version 13
  • Operating system: Linux Ubuntu 20

Declaration

Please complete the following declaration. If this declaration is not completed, your issue may be closed without comment.

Additional information

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions