[英]Is it possible to "open" vscode to see the contents of a docker container?
I have a docker image, and I am running it now (finishing with bash) When I do, I have a file structure inside the container.我有一个 docker 映像,我现在正在运行它(用 bash 完成)当我这样做时,我在容器内有一个文件结构。
However, this is not some file structure mapped (with -v) from outside the container.但是,这不是从容器外部映射(使用 -v)的某些文件结构。 These files and folders exist only inside the container.
这些文件和文件夹仅存在于容器内。
My question is, since it is bothersome to be opening each file with vi and navigating from the terminal, is there a way that I can open vscode on these files?我的问题是,因为用 vi 打开每个文件并从终端导航很麻烦,有没有办法可以在这些文件上打开 vscode?
Be aware that these files do not exist outside the container请注意,这些文件不存在于容器之外
我从这个链接找到了如何做到这一点但是我使用了“附加到正在运行的容器”命令
I rarely do that but when I have to I usually mount an empty volume to the container, then exec into the container copy the folder which I need into that empty volume, which is then replicated on my host machine.我很少这样做,但是当我必须时,我通常将一个空卷安装到容器中,然后执行到容器中,将我需要的文件夹复制到该空卷中,然后将其复制到我的主机上。 From my host machine I then open it in vscode.
然后从我的主机上在 vscode 中打开它。
However please be careful if you have sensitive information in that container, not to expose something by accident.但是,如果您在该容器中有敏感信息,请小心,不要意外暴露某些内容。
So the steps are:所以步骤是:
containerpath
is path which does not exist in the container prior to creating it. containerpath
是在创建容器之前不存在于容器中的路径。volume:
- ./hostpath:/containerpath
docker ps
docker exec -it <container_id> /bin/sh
cp -r folder containerpath
Exit the container and look at your files in ./hostpath
folder.退出容器并查看
./hostpath
文件夹中的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.