Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The "code" command does not work when connecting to a Docker container remotely with VSCode

I am using VSCode in my local PC and connecting to a Docker container in a remote server with VSCode's Extensions of Remote - SSH and Remote - containers. However, when I type

$ code <file name>

on the VSCode's terminal (Bash), I get an error messages saying that

bash: code: command not found

and I can't edit the file on the VSCode's editor.

If I click on the file from VSCode's Explorer (Ctrl+Shift+E), the edit screen will appear, but isn't it possible to call it with the code command?

Also, I call the command palette (Ctrl+Shift+P) and then search for Shell Command: Install 'code' command in PATH but no matching commands are found.

The execution environment is as follows:.

  • Local PC: Windows 10 Pro
  • Remote host PC: Ubuntu 18.04.3 LTS
  • Docker container in the remote host PC: Ubuntu 18.04.3 LTS

Thank you very much for your answer.

like image 419
akki Avatar asked Jan 25 '23 21:01

akki


1 Answers

I'll answer myself as I was able to call VSCode using the code command in the remote's container.

When I look closely underneath home, I see that there was a code at the following directory.

$HOME/.vscode-server/bin/<directory with a hash-like name>/bin/

So I passed the PATH through it and it worked.

By the way, <directory with a hash-like name> is a directory with a hash-like name, which is randomly assigned when you connect to the container remotely. It's different every time, so please refer to it by yourself.

The way to register the path is as follows.

export PATH="$PATH:$HOME/.vscode-server/bin/<directory with a hash-like name>/bin/"

Thank you very much for your support.

like image 174
akki Avatar answered Jan 29 '23 07:01

akki