简体   繁体   中英

VSCode Remote Container — how to open the default folder in the container instance of VSCode?

Whenever I attach VSCode to a container, it starts with no specific folder opened. I want to open folder "/ado" on start and apply the workspace settings there. How can I achieve this?

When I open the folder manually, I start in the /root folder of the container.

.devcontainer.json:

{
    "name": "Portal Docker Environment",
    "dockerComposeFile": "docker-compose.yml",
    "service": "api",
    "workspaceFolder": "/ado",
    "cwd": "/ado",
    "extensions": [
        "ms-python.python",
        "visualstudioexptteam.vscodeintellicode"
    ]
}

docker-compose.yml:

portal:
  build: Dockerfiles/portal
  image: portal
  command: launch_portal.py
  volumes:
    - ./ado:/ado
  ports:
    - "6543"
    - "51000:51000"   # for ptvsd debugger
  env_file:
    - ./portal.env

I also had no luck finding the complete list of possible keywords available in .devcontainer.json. Can anyone point me in the right direction?


Update: Found the keyword reference for .devcontainer.json

Got a response in the Github ticket :

"When attaching to a running container it is not known what your current workspace folder is. Therefore the user has to pick the folder."

So, attaching to a contaioner and then automatically opening a specific folder isn't possible, it seems. But I discovered that F1 Remote-Containers: Reopen Folder in Container roughly gets me where I want to go.

F1 Remote-Containers: Open Named Container Configuration File

{
  "workspaceFolder": "/ado"
}

Then save, close the window and reattach it to the container.

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