Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clone repository in container volume with Docker Compose fails due to permissions for non-existant folder #5388

Open
Chuxel opened this issue Jul 27, 2021 · 14 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers plan-review PM-highlighted item determined to be P1 or P2
Milestone

Comments

@Chuxel
Copy link
Member

Chuxel commented Jul 27, 2021

Version: 1.59.0-insider
Commit: e8a59bc6f920e731b47f0bc72263e82aba8b796e
Date: 2021-07-22T05:13:00.851Z
Electron: 13.1.7
Chrome: 91.0.4472.124
Node.js: 14.16.0
V8: 9.1.269.36-electron.0
OS: Darwin x64 20.5.0

Steps to Reproduce:

  1. On macOS, verify your local docker file share configuration does not include the /workspace folder.
    image
  2. Create a repository with a .devcontainer folder in it based on Docker Compose. e.g. pick Python 3 + Postgres from here: https://github.com/Chuxel/empty/tree/python-postgres
  3. In a new window in VS Code, run "Clone repository in container volume..." on the repository

Expected: Docker Compose-based dev containers start
Actual: Errors. What appears to be happening is the existing "workspace folder" mount point in the docker compose file is still there, but ends up using the path inside the container instead... which is not allowed by Docker so a permissions error appears.

Starting empty_devcontainer_app_1 ... error

ERROR: for empty_devcontainer_app_1  Cannot start service app: Mounts denied: 
The path /workspaces/empty is not shared from the host and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.
See https://docs.docker.com/docker-for-mac for more info.

ERROR: for app  Cannot start service app: Mounts denied: 
The path /workspaces/empty is not shared from the host and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.
See https://docs.docker.com/docker-for-mac for more info.
ERROR: Encountered errors while bringing up the project.
[7584 ms] Command failed: docker-compose --project-name empty_devcontainer -f /workspaces/empty/.devcontainer/docker-compose.yml -f /tmp/docker-compose.repositoryContainer.yml up -d

Earlier in the log file you can see this path in the output:

[6533 ms] services:
  app:
    build:
      args:
        INSTALL_NODE: "true"
        NODE_VERSION: lts/*
        USER_GID: '1000'
        USER_UID: '1000'
        VARIANT: '3'
      context: /workspaces/empty
      dockerfile: .devcontainer/Dockerfile
    command: sleep infinity
    labels:
      vsch.local.repository: https://github.com/chuxel/empty
      vsch.local.repository.folder: empty
      vsch.local.repository.volume: empty-2ac6de8b1d5867ef93cf7058ea7e0781
    network_mode: service:db
    volumes:
    - /workspaces/empty:/workspace:cached
    - empty-2ac6de8b1d5867ef93cf7058ea7e0781:/workspaces:rw
  db:
    environment:
      POSTGRES_DB: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
    image: postgres:latest
    restart: unless-stopped
    volumes:
    - postgres-data:/var/lib/postgresql/data:rw
version: '3'
volumes:
  empty-2ac6de8b1d5867ef93cf7058ea7e0781:
    external: true
    name: empty-2ac6de8b1d5867ef93cf7058ea7e0781
  postgres-data: {}

In this case the docker-compose.yaml file includes the following:

    volumes:
      - ..:/workspace:cached

...which is required for the non-volume case.

If you add /workspace to your share config, it works even though the folder doesn't exist.

image

@Chuxel Chuxel added bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers labels Jul 27, 2021
@Chuxel
Copy link
Member Author

Chuxel commented Jul 27, 2021

//cc: @bamurtaugh as well

@EvanSchalton
Copy link

I'm still experiencing this issue (even after adding the imaginary /workspaces dir in the docker dashboard)
Anyone had any luck?

@cyndi5
Copy link

cyndi5 commented Jan 2, 2022

Appreciate the workaround @Chuxel . That workaround works for me, macOS, non-root user vscode. I'll watch the repo for updates. 🙌

@ijaouani
Copy link

ijaouani commented Sep 14, 2022

@Chuxel This workaround does not seem to work anymore on MacOS (we was using it since a long time) with latest version of Docker Desktop (4.12.0).

Have been able to repro using both 0.251.0 and prerelease v0.252.0 on a from scratch repo using nodejs-postgres devcontainer definition.

[7086 ms] Start: Run: docker-compose --project-name platform_devcontainer -f /workspaces/platform/.devcontainer/docker-compose.yml -f /tmp/docker-compose/docker-compose.devcontainer.containerFeatures-1663144450524.yml up -d --no-recreate
Building with native build. Learn about native build in Compose here: https://docs.docker.com/go/compose-native-build/
Starting platform_devcontainer_app_1 ... error

ERROR: for platform_devcontainer_app_1  Cannot start service app: error while creating mount source path '/host_mnt/workspaces/platform': mkdir /host_mnt/workspaces: input/output error

ERROR: for app  Cannot start service app: error while creating mount source path '/host_mnt/workspaces/platform': mkdir /host_mnt/workspaces: input/output error
ERROR: Encountered errors while bringing up the project.
[7938 ms] Error: Command failed: docker-compose --project-name platform_devcontainer -f /workspaces/platform/.devcontainer/docker-compose.yml -f /tmp/docker-compose/docker-compose.devcontainer.containerFeatures-1663144450524.yml up -d --no-recreate
[7939 ms]     at pF (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:222:2970)
[7939 ms]     at processTicksAndRejections (internal/process/task_queues.js:95:5)
[7939 ms]     at async dF (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:206:2361)
[7939 ms]     at async DF (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:263:2177)
[7939 ms]     at async to (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:263:3110)
[7939 ms]     at async Ak (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:383:8108)
[7939 ms]     at async Ok (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:383:7864)
[7959 ms] Exit code 1

I also tried with Docker Desktop For Linux (Ubuntu) with exactly the same symptom. The only diff is there is no way to put a fake path (it prevent Docker Desktop to actually start) so I have tried with / in File Sharing settings.

For now the only workaround that works for me was to remove these lines from docker-compose.yml def (since we are always cloning in a container volume and not using Open Folder in Container) :

volumes:
  - ..:/workspace:cached

But I think the root cause should be address.

@coreyperkins
Copy link

@Chuxel This workaround does not seem to work anymore on MacOS (we was using it since a long time) with latest version of Docker Desktop (4.12.0).

Have been able to repro using both 0.251.0 and prerelease v0.252.0 on a from scratch repo using nodejs-postgres devcontainer definition.

[7086 ms] Start: Run: docker-compose --project-name platform_devcontainer -f /workspaces/platform/.devcontainer/docker-compose.yml -f /tmp/docker-compose/docker-compose.devcontainer.containerFeatures-1663144450524.yml up -d --no-recreate
Building with native build. Learn about native build in Compose here: https://docs.docker.com/go/compose-native-build/
Starting platform_devcontainer_app_1 ... error

ERROR: for platform_devcontainer_app_1  Cannot start service app: error while creating mount source path '/host_mnt/workspaces/platform': mkdir /host_mnt/workspaces: input/output error

ERROR: for app  Cannot start service app: error while creating mount source path '/host_mnt/workspaces/platform': mkdir /host_mnt/workspaces: input/output error
ERROR: Encountered errors while bringing up the project.
[7938 ms] Error: Command failed: docker-compose --project-name platform_devcontainer -f /workspaces/platform/.devcontainer/docker-compose.yml -f /tmp/docker-compose/docker-compose.devcontainer.containerFeatures-1663144450524.yml up -d --no-recreate
[7939 ms]     at pF (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:222:2970)
[7939 ms]     at processTicksAndRejections (internal/process/task_queues.js:95:5)
[7939 ms]     at async dF (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:206:2361)
[7939 ms]     at async DF (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:263:2177)
[7939 ms]     at async to (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:263:3110)
[7939 ms]     at async Ak (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:383:8108)
[7939 ms]     at async Ok (/root/.vscode-remote-containers/dist/dev-containers-cli-0.251.0/dist/spec-node/devContainersSpecCLI.js:383:7864)
[7959 ms] Exit code 1

I also tried with Docker Desktop For Linux (Ubuntu) with exactly the same symptom. The only diff is there is no way to put a fake path (it prevent Docker Desktop to actually start) so I have tried with / in File Sharing settings.

For now the only workaround that works for me was to remove these lines from docker-compose.yml def (since we are always cloning in a container volume and not using Open Folder in Container) :

volumes:
  - ..:/workspace:cached

But I think the root cause should be address.

I also am running into this since upgrading to 4.12. With 4.11 I was able to remove the volumes from the docker-compose.yml but with 4.12 that does not work.

ERROR: for platform_devcontainer_myapp_1 Cannot start service myapp: error while creating mount source path '/host_mnt/workspaces/platform': mkdir /host_mnt/workspaces: input/output error

@daniellaera
Copy link

same error on macOS with node-postgres. any update?

@chrmarti
Copy link
Contributor

A more robust workaround is to change the bind mount in the docker-compose.yml to:

    volumes:
      - ../..:/workspaces:cached

and the workspace folder in the devcontainer.json to:

	"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

This way the extension overwrites the mount point at /workspaces. The extension always mounts the volume at /workspaces because it initially (when it needs to know) doesn't know the contents of the devcontainer.json and the docker-compose.yml yet.

@daniellaera
Copy link

thank you @chrmarti! works well on MacOS

@Chuxel
Copy link
Member Author

Chuxel commented Sep 29, 2022

@bamurtaugh @samruddhikhandale @joshspicer We may want to update our Docker Compose templates to mirror this since I think it's also the Codespaces default behavior, so we'd be more consistent too.

johnboyes added a commit to bb-mvp/kafka-pipeline that referenced this issue Oct 6, 2022
This is the [out of the box VS Code devcontainer that bundles Python,
Node and PostgreSQL][1].  The only amendment was to apply [the bug fix
for a bug with the docker compose volume][2], that prevented the
container from starting.

[1]: https://github.com/microsoft/vscode-dev-containers/tree/main/containers/python-3-postgres
[2]: microsoft/vscode-remote-release#5388 (comment)
johnboyes added a commit to bb-mvp/kafka-pipeline that referenced this issue Oct 11, 2022
This is the [out of the box VS Code devcontainer that bundles Python,
Node and PostgreSQL][1].  The only amendment was to apply [the bug fix
for a bug with the docker compose volume][2], that prevented the
container from starting.

[1]: https://github.com/microsoft/vscode-dev-containers/tree/main/containers/python-3-postgres
[2]: microsoft/vscode-remote-release#5388 (comment)
johnboyes added a commit to bb-mvp/kafka-pipeline that referenced this issue Oct 11, 2022
* Add Python devcontainer with Node & PostgreSQL

This is the [out of the box VS Code devcontainer that bundles Python,
Node and PostgreSQL][1].  The only amendment was to apply [the bug fix
for a bug with the docker compose volume][2], that prevented the
container from starting.

[1]: https://github.com/microsoft/vscode-dev-containers/tree/main/containers/python-3-postgres
[2]: microsoft/vscode-remote-release#5388 (comment)

* Add VS Code PostgreSQL extension on devcontainer

We use [the most popular VS Code PostgreSQL extension][3].

[3]: https://marketplace.visualstudio.com/items?itemName=ckolkman.vscode-postgres

* Install psql on devcontainer

[psql][4] is the command line client for PostgreSQL.

[4]: https://www.postgresql.org/docs/current/app-psql.html

* Add shellcheck extension on devcontainer

* Add Java to devcontainer (needed for Liquibase)

Java is installed on the devcontainer as a [devcontainer feature][5],
which makes the installation very easy.

[5]: https://containers.dev/features

* Install Liquibase on devcontainer

[Liquibase][6] is an open source tool for versioning database changes.

[6]: https://www.liquibase.org/

* Create transaction database table via liquibase

* Seed database with 3 initial transactions

* Add liquibase update script

* Add script to create database if it does not exist

See https://stackoverflow.com/a/18389184

* Create & populate database on devcontainer startup

Using the [devcontainer postcreate command][7] for this.

[7]: https://containers.dev/implementors/json_reference/#lifecycle-scripts

* Run Liquibase in headless mode

We run it in headless mode because we are invoking it from a script
which gets automatically invoked by the devcontainer as a [postcreate
command][8].

[8]: https://containers.dev/implementors/json_reference/#lifecycle-scripts
@arianitu
Copy link

@chrmarti do you happen to have a workaround for when you pick a different workspaceFolder?

In our case, we have this config:

"workspaceFolder": "/var/www/html",

But I cannot get Clone in Volume to work with this setup and the only examples I see are for /workspaces example. The only thing I can think of is to symlink /workspaces to /var/www/html but it's a bit odd since it works fine with mounted git files, it only fails with Clone in Container Volume.

Does workspaceFolder not work for Clone in Container volume?

@arianitu
Copy link

arianitu commented Dec 1, 2022

I was able to get it work by doing this (not the cleanest method, honestly would prefer if workspaceFolder worked):

	"postAttachCommand": "rm -r /var/www/html && ln -s /workspaces/${localWorkspaceFolderBasename} /var/www/html"

Unfortunately I could not find a way to use workspaceFolder directly for both Mounted and In Volume methods. The In Volume method would always fail if I specified /var/www/html as the workspaceFolder. I do think that's a bug tho?

@Dzivo
Copy link

Dzivo commented Oct 28, 2023

A more robust workaround is to change the bind mount in the docker-compose.yml to:

    volumes:
      - ../..:/workspaces:cached

and the workspace folder in the devcontainer.json to:

	"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

This way the extension overwrites the mount point at /workspaces. The extension always mounts the volume at /workspaces because it initially (when it needs to know) doesn't know the contents of the devcontainer.json and the docker-compose.yml yet.

This was a workaround but this can not be the end solution :) thx for your hard work

@alexandrosraikos
Copy link

Any updates on this?

@tamazon
Copy link

tamazon commented Jul 30, 2024

I tried OrbStack instead of Docker Desktop on macos and it solved the issue for some reason.
I guess this is a bug in Docker Desktop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug containers Issue in vscode-remote containers plan-review PM-highlighted item determined to be P1 or P2
Projects
None yet
Development

No branches or pull requests