Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

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

Open
joezappie opened this issue Jun 14, 2022 · 4 comments
Assignees
Labels
containers info-needed Issue requires more information from poster

Comments

@joezappie
Copy link

joezappie commented Jun 14, 2022

  • 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
Copy link
Author

joezappie commented Jun 15, 2022

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.

@bamurtaugh
Copy link
Member

cc @chrmarti for any thoughts.

@marknelissen
Copy link

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.

@chrmarti
Copy link
Contributor

chrmarti commented Nov 1, 2022

microsoft/vscode-remote-release#5388 (comment) 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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
containers info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants