简体   繁体   中英

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.

However, this is not some file structure mapped (with -v) from outside the container. 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?

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.

However please be careful if you have sensitive information in that container, not to expose something by accident.

So the steps are:

  • Create empty volume ( docker-compose example ) Note do not overwrite the folder/file which you want to extract. containerpath is path which does not exist in the container prior to creating it.
volume:
  - ./hostpath:/containerpath
  • Find docker id so that you can use it to exec into it:
docker ps
  • Exec into the container:
docker exec -it <container_id> /bin/sh
  • Copy the file/folder to that empty volume:
cp -r folder containerpath

Exit the container and look at your files in ./hostpath folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM