You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@sr229
thank you for this idea - I have just tested it.
I have the feeling that ext install <package name> does not work outside the GUI/browser?
If I am mistaken, please let me know.
I would like to be able to install extensions from the command line - before accessing code-server in the browser.
I am looking for something like the VSCode feature of working with extensions from the command line.
How it is done in VSCode is also documented here.
@jeasonstudio I think this goes into the right direction, thank you.
Unfortunately, my javascript is not good enough to adapt build/tasks to my needs.
Is there anything I can do (e.g. yarn ... ) to install an extension after the pre-built container is running?
I would like to enter the running container from codercom/code-server, and run a command for installation of a package.
@jeasonstudio Thank you for the hint.
I suppose this is not an option for my situation, considering that I just want to pull and start the container.
At maximum, I would extend the Dockerfile.
Nonetheless, I will check out code-server again in a few months.
Very impressive and useful so far!
As far as I am concerned, this issue can be closed.
Of course you can leave it open, if you feel like implementing this feature down the road.
@ThorbenJensen I think you can do this by just extending the Dockerfile as @jeasonstudio suggests.
For example, the following installs the Preview extension. I needed it because I couldn't get the built-in Preview functions to work out-of-the-box and also it comes with Mermaid diagram support, which the built-in previewer does not.
RUN apt-get update && apt install -y bsdtar curl
RUN mkdir -p /root/.local/share/code-server/extensions
RUN curl -JL https://marketplace.visualstudio.com/_apis/public/gallery/publishers/searKing/vsextensions/preview-vscode/2.0.3/vspackage | bsdtar -xvf - extension
RUN mv extension /root/.local/share/code-server/extensions/searKing.preview-vscode-2.0.3
The lines above do the following.
Install bsdtar and curl. We install bsdtar because gnutar, which ships with Ubuntu and Debian, doesn't function properly with the archives we get from the Visual Studio web site.
Create an extensions subdirectory for the code-server data directory. The data directory path above (/root/.local/share/code-server/) is the default from what I can tell. You can look at the logs to verify that it's the same with your configuration. You'll see something like INFO Initializing {"data-dir":"/root/.local/share/code-server","working-dir": ...,"log-dir": ...} when starting the container.
Download and extract the extension file from the Visual Studio web site. The URL follows the form https://marketplace.visualstudio.com/_apis/public/gallery/publishers/<PUBLISHER>/vsextensions/<EXTENSION-NAME>/<VERSION>/vspackage. We only extract the extension folder.
Move the extension folder to a properly named folder of the form <PUBLISHER>.<EXTENSION-NAME>-<VERSION> in the extensions subdirectory.
If all goes well, you should be able to get the following.
Hope this helps!
Reacted by Yohan Courbe, Jonathan Owen, Ayase Minori, Jeason, Colin Adler, Tongyu, Mike Simpson, mirekphd, Tim Shaker, Allan Oricil and 4 more
@faustomorales great ideas, thanks a lot!
It appears that the extension folder in the container I extended from codercom/code-server is located at /root/.code-server/extensions.
So, heavily inspired by what you suggested, this is the Dockerfile that works for me:
FROM codercom/code-server
RUN apt-get update && apt-get -y upgrade
# VSCode extensions
RUN apt-get install -y bsdtar curl
RUN mkdir -p /root/.code-server/extensions
RUN curl -JL https://github.com/Microsoft/vscode-python/releases/download/2019.2.5558/ms-python-release.vsix | bsdtar -xvf - extension
RUN mv extension /root/.code-server/extensions/ms-python.python-vscode-2.0.3
CMD ["code-server", "--allow-http", "--no-auth"]
If anyone is interested in testing this Dockerfile:
@faustomorales great ideas, thanks a lot!
It appears that the extension folder in the container I extended from codercom/code-server is located at /root/.code-server/extensions.
So, heavily inspired by what you suggested, this is the Dockerfile that works for me:
FROM codercom/code-server
RUN apt-get update && apt-get -y upgrade
# VSCode extensions
RUN apt-get install -y bsdtar curl
RUN mkdir -p /root/.code-server/extensions
RUN curl -JL https://github.com/Microsoft/vscode-python/releases/download/2019.2.5558/ms-python-release.vsix | bsdtar -xvf - extension
RUN mv extension /root/.code-server/extensions/ms-python.python-vscode-2.0.3
CMD ["code-server", "--allow-http", "--no-auth"]
If anyone is interested in testing this Dockerfile:
I tried your dockerfile above and it fails to build and here is the output from the build.
I am getting permission denied. I want to install extension and could you please provide any reference to doc or Dockerfile which works.?
docker build . -t code-server-test
Sending build context to Docker daemon 2.048kB
Step 1/7 : FROM codercom/code-server
---> 9ea98ff48a65
Step 2/7 : RUN apt-get update && apt-get -y upgrade
---> Running in c57c1d8273f9
Reading package lists...
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
The command '/bin/sh -c apt-get update && apt-get -y upgrade' returned a non-zero code: 100
@jagraj The recommended way to install extensions now is to use code-server --install-extension <value>. You can give it the path to a .vsix file or the ID (looks like organization.extension-name).
Reacted by Kristie Howard, Jayesh Sharma, divya-antelligent, at8-bot, LinXiang, alang, Garrett Delfosse, renamedquery, Hunt Zhan, PC and 2 more
@jagraj The recommended way to install extensions now is to use code-server --install-extension <value>. You can give it the path to a .vsix file or the ID (looks like organization.extension-name).
Note that while it does work, it imposes a root requirement on the containerized system, iow VS Code now works only for root-owned containers. Trying to run it as non-root (e.g. docker run -u 1001) causes blank screen to be displayed in the browser instead of VS Code (which now works only for docker run -u 0 ). If you insert code-server --install-extension code in the root-owned part of the Dockerfile (before switch to non-root user, e.g. via USER coder), the extension would not be installed (would not be visible when running the container as a non-root user, here: coder with id 1001).
RUN mkdir -p /root/.local/share/code-server/extensions
@faustomorales , I think the default location for VS extensions can be made more general to allow for non-root containers, thus:
USER username
RUN mkdir -p ~/.local/share/code-server/extensions
@deansheather , hard-coding root folder in the default extensions location may be the reason why the new code-server --install-extension option works only for containers run with root UID.
More info
In containers run under non-root users (required e.g. in Openshift) extensions are either not available to such users or VS Code fails to appear, displaying blank screen, depending on who installed the extension in the Dockerfile, root or standard user. More precisely, calling RUN code-server --install-extension in your Dockerfile:
imposes root requirement if it follows USER coder in the Dockerfile (-u 10001 switch no longer works, you need to use the default -u 0 to see the VS Code web interface) or
fails to install the extension (for non-root users) if it precedes USER coder in the Dockerfile.
Reacted by Laurentiu Soica, CSCaudill and Nirajan Thakuri
@sanjayme97 I needed a container for python data science running on EC2 with code-server up and running. This is my custom dockerfile which builds successfully
FROM python:3.7.7-slim
WORKDIR /home
RUN /bin/bash -c "apt-get update -y;apt-get install wget -y"
RUN wget https://github.com/cdr/code-server/releases/download/3.2.0/code-server-3.2.0-linux-x86_64.tar.gz
RUN tar -xzvf code-server-3.2.0-linux-x86_64.tar.gz
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
ENV PASSWORD=demo
CMD /bin/bash -c "./code-server-3.2.0-linux-x86_64/code-server --install-extension ms-python.python --force --install-extension ms-azuretools.vscode-docker --force && ./code-server-3.2.0-linux-x86_64/code-server --host 0.0.0.0 --port 8989"
See if this works. extensions can be separated to a single run command too. But I have put this up hastly and haven't tested that approach
Linking to this issue, this is still an issue. Some extensions are not found
root@5844681dad51:/build# code-server --install-extension ms-vscode.cpptools
Installing extensions...
Extension 'ms-vscode.cpptools' not found.
Make sure you use the full extension ID, including the publisher, e.g.: ms-dotnettools.csharp
Failed Installing Extensions: ms-vscode.cpptools
or if you try to install them from .vsix you get something like this
root@5844681dad51:/build# code-server --install-extension clang-tidy.vsix
Installing extensions...
Error: End of central directory record signature not found. Either not a zip file, or file is truncated.
at v (/usr/lib/code-server/lib/vscode/out/vs/server/node/server.main.js:106:2390)
at /usr/lib/code-server/lib/vscode/out/vs/server/node/server.main.js:106:3833
at /usr/lib/code-server/lib/vscode/node_modules/yauzl/index.js:40:7
at /usr/lib/code-server/lib/vscode/node_modules/yauzl/index.js:190:5
at /usr/lib/code-server/lib/vscode/node_modules/yauzl/index.js:712:5
at /usr/lib/code-server/lib/vscode/node_modules/yauzl/fd-slicer.js:33:7
at FSReqCallback.wrapper [as oncomplete] (node:fs:686:5) {
code: 'Extract',
name: 'Extract'
}
Failed Installing Extensions: file:///build/clang-tidy.vsix
As for the extract error, that makes it seem very likely that the vsix is corrupted. Are you able to unzip it on the command line? Might need to download it again.
Activity
sr229 commentedon Mar 11, 2019
@ThorbenJensen have you tried using
ext install <package name>?top-on commentedon Mar 11, 2019
@sr229
thank you for this idea - I have just tested it.
I have the feeling that
ext install <package name>does not work outside the GUI/browser?If I am mistaken, please let me know.
I would like to be able to install extensions from the command line - before accessing code-server in the browser.
I am looking for something like the VSCode feature of working with extensions from the command line.
How it is done in VSCode is also documented here.
jeasonstudio commentedon Mar 11, 2019
@ThorbenJensen I guess you want to pre-load some extensions before running.
yarn task build:copy-vscodeinbuild/tasks.ts#171may help.top-on commentedon Mar 11, 2019
@jeasonstudio I think this goes into the right direction, thank you.
Unfortunately, my javascript is not good enough to adapt
build/tasksto my needs.Is there anything I can do (e.g.
yarn ...) to install an extension after the pre-built container is running?I would like to enter the running container from
codercom/code-server, and run a command for installation of a package.jeasonstudio commentedon Mar 12, 2019
@ThorbenJensen For now, you can just copy
extension folderto$HOME/.code-server/extensions. It will work.top-on commentedon Mar 12, 2019
@jeasonstudio Thank you for the hint.
I suppose this is not an option for my situation, considering that I just want to pull and start the container.
At maximum, I would extend the Dockerfile.
Nonetheless, I will check out code-server again in a few months.
Very impressive and useful so far!
As far as I am concerned, this issue can be closed.
Of course you can leave it open, if you feel like implementing this feature down the road.
faustomorales commentedon Mar 17, 2019
@ThorbenJensen I think you can do this by just extending the Dockerfile as @jeasonstudio suggests.
For example, the following installs the Preview extension. I needed it because I couldn't get the built-in Preview functions to work out-of-the-box and also it comes with Mermaid diagram support, which the built-in previewer does not.
The lines above do the following.
bsdtarandcurl. We installbsdtarbecausegnutar, which ships with Ubuntu and Debian, doesn't function properly with the archives we get from the Visual Studio web site.extensionssubdirectory for thecode-serverdata directory. The data directory path above (/root/.local/share/code-server/) is the default from what I can tell. You can look at the logs to verify that it's the same with your configuration. You'll see something likeINFO Initializing {"data-dir":"/root/.local/share/code-server","working-dir": ...,"log-dir": ...}when starting the container.https://marketplace.visualstudio.com/_apis/public/gallery/publishers/<PUBLISHER>/vsextensions/<EXTENSION-NAME>/<VERSION>/vspackage. We only extract theextensionfolder.<PUBLISHER>.<EXTENSION-NAME>-<VERSION>in theextensionssubdirectory.If all goes well, you should be able to get the following.
Hope this helps!
yohancourbe commentedon Mar 17, 2019
A lightweight alternative could be to use workspace recommended extensions
sabrehagen commentedon Mar 19, 2019
This is currently not supported. What needs to be done to enable workspace extensions team?
top-on commentedon Mar 20, 2019
@faustomorales great ideas, thanks a lot!
It appears that the extension folder in the container I extended from
codercom/code-serveris located at/root/.code-server/extensions.So, heavily inspired by what you suggested, this is the Dockerfile that works for me:
If anyone is interested in testing this Dockerfile:
Thanks, again :-)
coadler commentedon Apr 20, 2019
Resolved in #504
jagraj commentedon Jul 31, 2019
@ThorbenJensen
I tried your dockerfile above and it fails to build and here is the output from the build.
I am getting permission denied. I want to install extension and could you please provide any reference to doc or Dockerfile which works.?
deansheather commentedon Aug 2, 2019
@jagraj The recommended way to install extensions now is to use
code-server --install-extension <value>. You can give it the path to a.vsixfile or the ID (looks likeorganization.extension-name).top-on commentedon Aug 2, 2019
@jagrag I can confirm that
code-server --install-extension <value>is the new install mechanism that works. You see an example in the Dockerfile here:https://github.com/ThorbenJensen/code-server-blueprint/blob/master/Dockerfile
mirekphd commentedon Nov 22, 2019
Note that while it does work, it imposes a root requirement on the containerized system, iow VS Code now works only for root-owned containers. Trying to run it as non-root (e.g.
docker run -u 1001) causes blank screen to be displayed in the browser instead of VS Code (which now works only fordocker run -u 0). If you insertcode-server --install-extensioncode in the root-owned part of the Dockerfile (before switch to non-root user, e.g. viaUSER coder), the extension would not be installed (would not be visible when running the container as a non-root user, here: coder with id 1001).mirekphd commentedon Nov 23, 2019
@faustomorales , I think the default location for VS extensions can be made more general to allow for non-root containers, thus:
@deansheather , hard-coding root folder in the default extensions location may be the reason why the new
code-server --install-extensionoption works only for containers run with root UID.More info
In containers run under non-root users (required e.g. in Openshift) extensions are either not available to such users or VS Code fails to appear, displaying blank screen, depending on who installed the extension in the Dockerfile, root or standard user. More precisely, calling
RUN code-server --install-extensionin your Dockerfile:USER coderin the Dockerfile (-u 10001switch no longer works, you need to use the default-u 0to see the VS Code web interface) orUSER coderin the Dockerfile.nailson-landim commentedon Jan 26, 2020
Thanks @faustomorales!
sanjayme97 commentedon Apr 9, 2020
above solutions are not working? any more solutions? @faustomorales @ThorbenJensen @coadler
rahulkhanna2 commentedon May 13, 2020
@sanjayme97 I needed a container for python data science running on EC2 with code-server up and running. This is my custom dockerfile which builds successfully
See if this works. extensions can be separated to a single run command too. But I have put this up hastly and haven't tested that approach
hgrattenthaler commentedon Aug 15, 2024
Linking to this issue, this is still an issue. Some extensions are not found
or if you try to install them from .vsix you get something like this
code-asher commentedon Aug 16, 2024
code-server uses Open VSX for the extension marketplace and the cpptools extension is not on there so there is unfortunately nothing we can do about it. microsoft/vscode-cpptools#12269 (comment)
As for the extract error, that makes it seem very likely that the vsix is corrupted. Are you able to unzip it on the command line? Might need to download it again.
hgrattenthaler commentedon Aug 16, 2024
Yes, bsdtar is able to unzip the file, however this does not seem to be what code-server uses, so it fails.
code-asher commentedon Aug 16, 2024
Oh interesting. I think VS Code is using https://github.com/thejoshwolfe/yauzl