vscode-dev-containers icon indicating copy to clipboard operation
vscode-dev-containers copied to clipboard

Mounted folder is empty when Cloned from Repo (works when opened from local files)

Open joezappie opened this issue 2 years ago • 4 comments

  • 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

image

When using VS Code to "Clone the repo into a container volume", this however does not work and the folder is empty.

image

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

joezappie avatar Jun 14 '22 05:06 joezappie

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.

joezappie avatar Jun 15 '22 03:06 joezappie

cc @chrmarti for any thoughts.

bamurtaugh avatar Jun 27 '22 16:06 bamurtaugh

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:

  1. start new git repo with readme
  2. checkout git repo in volume (in vs code)
  3. go through the wizard to generate the devcontainer files
  4. when opening the dev container, it fails on a failed mount bind
  5. select the option to edit the config in recovery container
  6. apply the workaround from @jrj2211 to the config files
  7. restart in dev container
  8. this fails again
  9. manually delete the "old" dev container for the app portion from docker
  10. reboot in dev container
  11. the environment boots up and I'm connected
  12. 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.

marknelissen avatar Oct 25 '22 14:10 marknelissen

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?

chrmarti avatar Nov 01 '22 08:11 chrmarti