Videos
For me it worked the workspaceMount instead of mount
"workspaceMount": "source=${localWorkspaceFolder}/sub-folder,target=/workspace,type=bind,consistency=delegated",
"workspaceFolder": "/workspace"
as stated in https://code.visualstudio.com/docs/remote/containers-advanced
Docker-in-Docker
Using docker-compose
When working with a Docker-in-Docker setup which utilizes the docker-compose functionality, the VSCode internal variable ${localWorkspaceFolder} can be used to get the actual path to the workspace on disk. This is needed because in a Docker-in-Docker environment, "normal" paths may not work as the first Docker instance is already running in a mounted environment.
In order to make those internal VSCode variables also accessible in the docker-compose.yaml, you first need to define an environment variable in your .devcontainer/devcontainer.json:
{
"name": "DevContainer",
"dockerFile": "Dockerfile", // this is a reference to the .devcontainer/Dockerfile, which is used by VSCode to build the DevContainer. This has nothing to do with the Dockerfile or docker-compose.yaml file your project is using.
"remoteEnv": {
// the original host directory which is needed for volume
// mount commands from inside the container (Docker in Docker)
"HOST_PROJECT_PATH": "${localWorkspaceFolder}"
}
}
Then, use the environment variable in your project's actual ./docker-compose.yaml:
services:
webserver:
image: nginx:mainline-alpine
container_name: webserver
ports:
- 8080:80
volumes:
- ${HOST_PROJECT_PATH}/webserver:/etc/nginx/conf.d
- ${HOST_PROJECT_PATH}/build:/var/www/html
VSCode provides even more internal variables which can be used for advanced setup and configuration of the DevContainer environment. Please have a look here.
Using Dockerfile
More information on how to use Docker-in-Docker with Dockerfiles can be found here.