vscode-dev-containers icon indicating copy to clipboard operation
vscode-dev-containers copied to clipboard

docker-from-docker bind mount documentation incorrect for codespaces

Open mgabeler-lee-6rs opened this issue 3 years ago • 8 comments

  • 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:

  1. Setup a codespace devcontainer with docker-from-docker enabled
  2. 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?)

mgabeler-lee-6rs avatar Dec 17 '21 06:12 mgabeler-lee-6rs

@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?

Chuxel avatar Jan 03 '22 15:01 Chuxel

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

AsyncVoid avatar Jul 28 '22 13:07 AsyncVoid

@joshspicer @jkeech ?

Chuxel avatar Jul 28 '22 14:07 Chuxel

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

jkeech avatar Jul 28 '22 15:07 jkeech

There are definitely workarounds. The point of this ticket is that

The documentation is wrong

:grinning:

mgabeler-lee-6rs avatar Jul 28 '22 17:07 mgabeler-lee-6rs

@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.

jkeech avatar Jul 28 '22 17:07 jkeech

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 avatar Aug 02 '22 05:08 AsyncVoid

@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.

jkeech avatar Aug 02 '22 16:08 jkeech