skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    I found how to do it from this link However I used the "attach to running container" command


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search