vscode-dev-containers
vscode-dev-containers copied to clipboard
Mounted folder is empty when Cloned from Repo (works when opened from local files)
- VSCode Version: 1.68.0
- Local OS Version: Windows 10.0.19044
- Local chip architecture: arm64
- Reproduces in: Remote - Containers (codespaces untested)
- Name of Dev Container Definition with Issue: mongodb
I need to run a bash script in a container to initialize a mongo replica set. To do this I need to mount my .devcontainer folder to a mongodb setup container so it can run it. This works if I checkout the repo locally and then run "Rebuild and reopen in Container"
Here is a demo repository that the issue occurs for me: https://github.com/jrj2211/vscode-remote-try-node-mongo-compose
When using VS Code to "Clone the repo into a container volume", this however does not work and the folder is empty.
I was expecting these would work the same, regardless if its a local source or pulled from git in a docker volume.
I imagine the first thing that happens is dev containers clone the git directory into a volume so I'm unsure why its not available in this way. In the "app" service once booted into the terminal, the files all exist in the /workspaces/vscode-remote-try-node-mongo-compose
directory.
I've also tried move this script into various directories. Even if you mount ..:/workspace
, id expect to see the test-project and .devcontainer folders in there but it too is empty. Mounting just the script itself also does not work.
I've been unable to find a workaround for this.
The documentation on his page makes it seem like this should be doable: https://code.visualstudio.com/remote/advancedcontainers/add-local-file-mount
I found a workaround for this: https://github.com/h4l/dev-container-docker-compose-volume-or-bind
That makes it so it works either locally or cloned in a volume.
I'm still unsure why the notation .:/workspace
doesn't work however. Will this ever be supported or will passing environment variables to docker-compose via another bash script always be needed? That method, while clever, feels hacky/complex and like it should be supported out of the box.
cc @chrmarti for any thoughts.
I'm struggling with this as well, and using the workaround posted by @jrj2211 , but it makes it difficult to setup the dev container in the first place, since if you start from the "Node.js and Mongo" predefined setup when you checkout a new repo (no devcontainer config yet), it will create a mount to /workspace
that does not work, and even if you add the workaround, the mount will not be removed. The only way to startup a new project is:
- start new git repo with readme
- checkout git repo in volume (in vs code)
- go through the wizard to generate the devcontainer files
- when opening the dev container, it fails on a failed mount bind
- select the option to edit the config in recovery container
- apply the workaround from @jrj2211 to the config files
- restart in dev container
- this fails again
- manually delete the "old" dev container for the app portion from docker
- reboot in dev container
- the environment boots up and I'm connected
- I push the devcontainer files to the git repo
Only after 10 do I have a working environment from which I can then push the config files to the git repo. This is a long process, and it's not easy to always put back together the different pieces when starting up a new project. The process should actually only consist of steps 1, 2, 3, 11, 12, which is the flow when using a simple Dockerfile based devcontainer, like when using the predefined Typescript image.
https://github.com/microsoft/vscode-remote-release/issues/5388#issuecomment-1259437096 describes a setup where you align the bind mount with the volume mount that replaces it when cloning the repo to a volume. Does that work for you?