1

I'm setting up a vscode dev container that uses docker-compose. I need to initalize a replica set in mongo which uses a 2nd setup container that needs a bash script.

My directory structure is:

.devcontainer
  scripts
    mongosetup.sh

I'm then mounting the scripts directory to my container:

mongodb-setup:
    image: mongo
    volumes:
      - ./scripts:/scripts
    command: "ls -la /scripts"
    depends_on:
      - mongodb

Checking the output from this container, the ls -la /scripts command shows that mongosetup.sh has been made a folder so I can't run it...

total 4
drwxr-xr-x 3 root root   60 Jun 14 02:29 .
drwxr-xr-x 1 root root 4096 Jun 14 03:25 ..
drwxr-xr-x 2 root root   40 Jun 14 02:29 mongosetup.sh

I've tried mounting just the file and my volume as ".scripts:/scripts".

I should note that this only happens when using "Clone repository in Container volume". If I clone the repo to my computer, than open it in VS code and build it from there it works fine.

My devcontainer is setup to go into my mongodb image. It has access to my files in /workspaces/REPONAME and if I check it there the file is not a folder:

enter image description here

Joe Jankowiak
  • 1,059
  • 12
  • 37
  • Related issue: https://stackoverflow.com/a/44950494/14032355 The underlying reason causing the file being shared with -v to appear as a directory instead of a file is that Docker could not find the file on the host. So Docker creates a new directory in the container with the name being the name of the non existing file on the host as docker thinks that the user just want to share a volume/directory that will be created in the future. – ikhvjs Jun 14 '22 at 08:29
  • Thank you. I did try to mount the file individually in that location which now makes sense why it exists as a folder. So that leads me to another issue of why its not getting mounted but I'll make a new question for that as I now have a demo repo for the issue. – Joe Jankowiak Jun 14 '22 at 17:48
  • I think [this](https://stackoverflow.com/a/65323532/4340793) solution might help you. – JeyJ May 27 '23 at 10:36

1 Answers1

0

As pointed out by @ikhvjs in the comments, this is due to the file not being found so Docker automatically makes it a directory.

I had previously tried mounting just the file itself in that location so Docker created the directory. When it didn't work, I changed the mount to be the directory above it, causing the folder to still be there and leading to my confusion.

Joe Jankowiak
  • 1,059
  • 12
  • 37
  • did u find a solution ? – JeyJ May 24 '23 at 09:30
  • Unfortunately no. I'm just using a health check to initialize the mongo replication server but I still dislike that as a solution. Hopefully one day Microsoft improve the docker volume support in devcontainers. – Joe Jankowiak May 26 '23 at 23:05