vscode-dev-containers
vscode-dev-containers copied to clipboard
docker-from-docker bind mount documentation incorrect for codespaces
- VSCode Version: N/A
- Local OS Version: N/A
- Reproduces in: Codespaces
- Name of Dev Container Definition with Issue: docker-from-docker
Steps to Reproduce:
- Setup a codespace devcontainer with docker-from-docker enabled
- Try to run a container that bind mounts
/workspaces
The documentation at https://github.com/microsoft/vscode-dev-containers/tree/main/containers/docker-from-docker#using-bind-mounts-when-working-with-docker-inside-the-container states:
In GitHub Codespaces, the workspace folder is available in the same place on the host as it is in the container, so you can bind workspace contents as you would normally.
Empirically, this seems to simply be untrue now. The /workspaces folder inside the container is actually at /var/lib/docker/codespacemount/workspace (note: workspace not workspaces on the host because ... who knows?)
@joshspicer Is this actually a Codespaces bug? Do we no longer create a symlink on the host to the location where the bind mount would land inside the container for this scenario?
I can confirm it does not work when trying to mount a file/folder when creating a container or when using a Dockerfile with COPY. Docker says the file cannot be found. It works fine on my PC with the same docker version. It does not work irrespective of the docker-compose version (tried v1 and v2) on Codespaces
Example
It does not work with:
FROM nginx
COPY ./nginx.conf /etc/nginx/nginx.conf
OR
FROM nginx
COPY /workspaces/some-codespace-repo/data/nginx.conf /etc/nginx/nginx.conf
I can confirm the file exists, when I click the link in the terminal the file opens in vscode.
But it does work with:
FROM nginx
COPY /var/lib/docker/codespacemount/workspace/some-codespace-repo/data/nginx.conf /etc/nginx/nginx.conf
@joshspicer @jkeech ?
I would recommend using the relative path approach. What is the Docker context set to for the build? From the examples you provided, it looks like the relative path might be wrong. Does changing it to ./data/nginx.conf or ../data/nginx.conf work? If not, can you share the repo where you are hitting issues?
FROM nginx
COPY ./data/nginx.conf /etc/nginx/nginx.conf
There are definitely workarounds. The point of this ticket is that
The documentation is wrong
:grinning:
@mgabeler-lee-6rs thanks for pointing that out! I did some digging, and it looks like we used to have a feature in Codespaces that would symlink the repo root (/workspaces/{repo}) to the same path on the host so that bind mounts for docker-from-docker or compose configurations could use the simpler path that you see inside the container and it would just work, even though it was building on the host. That feature got removed about a year ago, but I just opened a bug internally to bring it back. So yes, the readme for that feature is wrong currently. We'll fix it in Codespaces to make that statement true again.
In general, I would still recommend the relative path over the absolute path since it's likely to work better across different runtimes if you use the repo in both Codespaces and Remote - Containers.
Yes relative path does not work either, you have to specify the whole path on the host in this case. All paths were certainly right as I can open them in code with CTRL+Click and I see no other files/folders being created by docker. Thank you
@AsyncVoid do you mind opening a separate issue for the relative path error you are seeing? Relative path should work, but the path is relative to the Docker build context directory, which might not be the same as the directory where the devcontainer.json lives. It would depend on your exact devcontainer configuration.