Search code examples
windows-7docker-machinevscode-remotedocker-toolbox

How to use vscode remote containers with docker machine (and docker toolbox)?


I use Windows 7 and can't install Docker for Windows, so I use Docker Toolbox.

Docker Toolbox is not supported by Microsoft Visual Studio Code for Remote Container Development.

But I need to use this functionality with my docker toolbox.

There is an issue on Github not solved yet https://github.com/microsoft/vscode-remote-release/issues/95


Solution

  • Docker Toolbox was a product based on docker-machine and virtualbox to use a local VM. That VM has all your user profile shared by default, so you can share any folder on your profile with a container in the VM using the path /c/user/<profile_name>/folder/a/b.

    Warning: Be careful to avoid sharing all your user profile with an image you don't trust

    Steps to enable VSCode remote containers when using docker machine

    You need to start your docker-machine (tested with vscode 1.40.2+)

    In your .devcontainer.json you can overwrite the workspace mount volume command (More info here)

    "workspaceMount": "src=//c/Users/yourusername/git/reponame,dst=/workspaces/reponame,type=bind,consistency=delegated"

    VSCode search the default workspace inside the container in /workspaces with the same name as the original and opens it automatically, but you can override this in .devconatiner if you need or open it manually.

    Important: your repository should always be inside your windows user profile (%userprofile%). This is a requirement from Docker Toolbox default shares.

    Note: the problem with Docker Toolboox is that Visual Studio Code doesn't support the docker-machine path style to mount volumes by default. But this workaround can help you.

    Updated 2020/05/13

    Tested with 1.44 it still works but you can't use an environment variable to config mount paths yet. So each developer should customize the local path of the repo after clone the repository.

    Updated 2020/10/29 Microsoft added information about how to use VSCode remote containers with Docker Machine here. Microsoft docs let's you imagine what kind of path should you use because it doesn't assume that the docker-machine environment is a local VM. This is where you can found this answer useful.