如何在docker内愉快的使用vscode进行代码编写
-
先在官网下载好vscode的deb包
-
将deb包通过
docker cp
拷进docker内进行安装 -
在安装的时候如果报缺失相关的依赖,运行a
pt --fix-broken install
进行自动修复,然后重新安装即可 -
然后如果直接运行code会报以下的错误,因为docker内都是root权限,你需要用它提示的方法启动:
You are trying to start vscode as a super user which is not recommended. If you really want to, you must specify an alternate user data directory using the --user-data-dir argument.
-
带上
--user-data-dir
选项后,会生成一些配置文件什么的,所以建议专门建一个文件夹用于存放这些文件 -
然后再次打开vscode
code ../workspace/ --user-data-dir=.
,还会报一个错,缺少库导致的/usr/share/code/bin/../code: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory
-
通过apt安装一下就好了
sudo apt install --assume-yes libx11-xcb1 libasound2 x11-apps libice6 libsm6 libxaw7 libxft2 libxmu6 libxpm4 libxt6 x11-apps xbitmaps
-
现在你就可以成功打开vscode了,只是你还看不到。因为docker没有图形化界面可以显示
-
不要慌,参照我的这篇文章设置一下就好了《如何在docker内运行ROS2(dashing)的“小乌龟(turttlesim)”》
Now,enjoy it!