{"id":19059261,"url":"https://github.com/h4l/dev-container-docker-compose-volume-or-bind","last_synced_at":"2025-04-24T06:15:39.087Z","repository":{"id":37016905,"uuid":"478077356","full_name":"h4l/dev-container-docker-compose-volume-or-bind","owner":"h4l","description":"A template for Docker Compose devcontainers supporting both bind mounts and container volumes","archived":false,"fork":false,"pushed_at":"2023-06-09T15:12:42.000Z","size":12,"stargazers_count":26,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-24T06:15:31.458Z","etag":null,"topics":["dev-containers","devcontainers","docker-compose","vscode"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/h4l.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-05T10:24:21.000Z","updated_at":"2025-04-15T06:24:50.000Z","dependencies_parsed_at":"2022-08-18T07:10:33.576Z","dependency_job_id":null,"html_url":"https://github.com/h4l/dev-container-docker-compose-volume-or-bind","commit_stats":null,"previous_names":[],"tags_count":2,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h4l%2Fdev-container-docker-compose-volume-or-bind","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h4l%2Fdev-container-docker-compose-volume-or-bind/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h4l%2Fdev-container-docker-compose-volume-or-bind/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h4l%2Fdev-container-docker-compose-volume-or-bind/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h4l","download_url":"https://codeload.github.com/h4l/dev-container-docker-compose-volume-or-bind/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250573360,"owners_count":21452352,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dev-containers","devcontainers","docker-compose","vscode"],"created_at":"2024-11-09T00:07:30.240Z","updated_at":"2025-04-24T06:15:39.067Z","avatar_url":"https://github.com/h4l.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dev Container Example: Docker Compose with workspace in volume or bind mount\n\n## Summary\n\nAn example [Dev Container](https://code.visualstudio.com/docs/remote/containers)\nconfiguration for a Docker Compose project with workspace code accessed from the\nlocal filesystem via a bind mount, or with the project code in a Docker\ncontainer volume.\n\nThe project can be opened in Visual Studio Code via the command palette\n**Remote-Containers: Clone Repository in Container Volume...** or by opening a\nlocal checkout of the repository.\n\nSupporting both container volume workspaces and bind mount workspaces in a\nsingle Docker Compose dev container configuration is not easy at present.\nHopefully this example will become redundant in the near future if the Remote\nContainers plugin provides a way to consistently access workspace content from\nvolumes and bind mounts in Docker Compose services.\n\n## Using this example\n\n1. If this is your first time using a development container, please see getting started information on [setting up](https://aka.ms/vscode-remote/containers/getting-started) Remote-Containers.\n\n2. To open it from a container volume:\n\n    1. Start VS Code, press \u003ckbd\u003eF1\u003c/kbd\u003e and select **Remote-Containers: Clone\n       Repository in Container Volume...** and enter this repository's URL\n\n   Or to open it from the local filesystem:\n\n    1. Clone this repository on your computer\n\n    2. Start VS Code and open this project folder.\n\n    3. Press \u003ckbd\u003eF1\u003c/kbd\u003e and run **Remote-Containers: Reopen Folder in Container**\n\nTo use it in your own project, copy the `.devcontainer` directory from this\nrepository into your project and edit the `devcontainer.json` and\n`docker-compose.yml` as required. Make sure the\n`.devcontainer/gen-docker-compose-workspace-env.sh` script is marked executable\n(`chmod +x ...`).\n\nThe key parts are:\n\n* In `devcontainer.json` run the envar-generation script in `initializeCommand`:\n\n    ```json5\n    \"initializeCommand\": \".devcontainer/gen-docker-compose-workspace-env.sh --container-workspace-folder '${containerWorkspaceFolder}' --local-workspace-folder '${localWorkspaceFolder}'\"\n    ```\n* In `docker-compose.yml`:\n\n    * Access the workspace files in a service by defining the `volumes` entry:\n\n    ```yaml\n    volumes:\n      - ${WORKSPACE_SOURCE:?}:${WORKSPACE_TARGET:?}\n    ```\n\n    * And define this top-level volume:\n\n    ```yaml\n    volumes:\n      devcontainer-volume:\n        name: ${WORKSPACE_CONTAINER_VOLUME_SOURCE:-not-used-in-bind-mount-workspace}\n        external: ${WORKSPACE_IS_CONTAINER_VOLUME:?}\n    ```\n\n## Compatibility\n\n* The [Remote Containers] plugin has changed its behaviour between updates in\n  incompatible ways several times. Future updates could break this example\n  again.\n* The example has not been tested with GitHub Codespaces as I've not got an\n  account with access to it.\n\n[Remote Containers]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers\n\n## How it works\n\nThe [`devcontainer.json`] `\"initializeCommand\"` runs\n[`gen-docker-compose-workspace-env.sh`] which generates several environment\nvariables in `.devcontainer/.env` which vary depending on whether the workspace\nis in a container volume or a local bind mount.\n[`.devcontainer/docker-compose.yml`] references these environment variables when\ndefining its service volumes, which allows one Compose file to consistently\nhandle bind mounts and volume workspaces.\n\nRun [`gen-docker-compose-workspace-env.sh`] with `--help` or just read its help\ntext for more details.\n\n[`devcontainer.json`]: .devcontainer/devcontainer.json\n[`gen-docker-compose-workspace-env.sh`]: .devcontainer/gen-docker-compose-workspace-env.sh\n[`.devcontainer/docker-compose.yml`]: .devcontainer/docker-compose.yml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh4l%2Fdev-container-docker-compose-volume-or-bind","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh4l%2Fdev-container-docker-compose-volume-or-bind","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh4l%2Fdev-container-docker-compose-volume-or-bind/lists"}