运行 vscode 在 docker

Run vscode in docker

我想在docker中运行vscode进行内部测试,我创建了以下内容

FROM debian:stable

RUN apt-get update && apt-get install -y apt-transport-https curl gpg
RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \
 && install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/ \
 && echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list
RUN apt-get update && apt-get install -y code libx11-xcb-dev libasound2


RUN code --user-data-dir="~/.vscode-root"

我用来搭建

docker build -t vscode .

我习惯运行 docker run vscode code -v
当我 运行 像这样时,我得到了错误

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.

我只想通过 运行 验证它 RUN code -v 我该怎么做?

我应该更改用户吗?我只想在 docker 中 运行 vscode 并使用一些 vscode api

您是否尝试过使用 VSCode 的内置功能在容器中进行开发?

查看此页面,其中介绍了如何执行此操作:

Developing inside a Container

您可以试用 VSCode 提供的一些示例容器配置,并使用任何这些 devcontainer.json 文件作为示例来配置您喜欢的自定义开发容器。根据上面的页面:

Workspace files are mounted from the local file system or copied or cloned into the container. Extensions are installed and run inside the container, where they have full access to the tools, platform, and file system. This means that you can seamlessly switch your entire development environment just by connecting to a different container.

这是一种非常方便的方法,可以在容器中隔离不同的开发环境。