Example to show how to clone to a devcontainer in Visual Studio Code without an intermediary host bind mount
These setting are ignored when cloning into a volume.
// .devcontainer/devcontainer.json
{
// ...
"workspaceFolder": "/workspaces/example-devcontainer-volume",
"build": {
"dockerfile": "../Dockerfile",
"args": {}
},
// ...
}
When you clone into a volume, as opposed to opening a devcontainer from a repository already cloned in your host filesystem, the following differences take place:
- An anonymous volume is created
- A temporary container clones the repository into this volume
- Either the Dockerfile or a docker-compose in the root of the repository is used to create the Dev Container
- The devcontainer is created with the volume mounted at
/workspaces
inside the container - The workspace starts with the workspace directory of
/workspaces/${respositoryName}
- Visual Studio Code
- Dev Containers Extension
- Docker Desktop
To get started, follow these steps in Visual Studio Code.
- Run the Dev Containers: Clone Repository in Container Volume... command
- Enter the Git URL for this repository
https://github.com/kallangerard/example-devcontainer-volume.git
- VSCode will clone the repository into an anonymous volume and open the repository in a remote devcontainer workspace
To test that the repository was cloned into the devcontainer volume, run the following command in the integrated terminal.
pytest
=== test session starts ===
platform linux -- Python 3.11.1, pytest-7.2.0, pluggy-1.0.0
rootdir: /workspaces/example-devcontainer-volume
plugins: anyio-3.6.2
collected 1 item
example_api/test_main.py . [100%]
=== 1 passed in 0.10s ===
📘 Info You may need to create a new terminal in vscode after the virtual environment has been created
To start the development server, run the following command in the integrated terminal.
uvicorn example_api.main:app --reload
📘 Info You may need to create a new terminal in vscode after the virtual environment has been created
You should then be able to view the development server at http://localhost:8000 on your host machines web brwosers with code reloading