microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.71k stars 1.4k forks source link

docker-in-docker feature makes X11 bind mount not working #1303

Open mataslib opened 2 years ago

mataslib commented 2 years ago

Steps to Reproduce:

  1. this feature snippet inside devcontainer.json:
    "features": {
     "docker-in-docker": {
       "version": "latest",
       "moby": true
    }
    ...
  2. makes this snippet inside devcontainer.json not working:
    "runArgs": [
    "-v",
    "/tmp/.X11-unix:/tmp/.X11-unix"
    ],

    it makes ls -lah /tmp/.X11-unix/ no result, so I can't run gui app in docker container. When I comment 'docker-in-docker' snippet out, then it works.

Other mounts like this works fine, ls -lah /test has results:

"runArgs": [
    "-v",
    "/test:/test",
],
Chuxel commented 2 years ago

Docker in docker mounts some host locations - one of which being /tmp. https://github.com/moby/moby/blob/ea5b4765d9d9a5aa5cab39f7119cffe74be874ce/hack/dind#L24

If you use Docker Desktop with WSL, this mount point is likely in the Docker Desktop WSL distro rather than the one you are using. I'm not sure there's a workaround.

I'd recommend looking at the desktop-lite script rather than using X forwarding. X tends to be slow in comparison.

mataslib commented 2 years ago

Thanks for your help. I'm sorry, but i'm not a docker/OS expert, just a humble web dev, so I can't help solve this much.

I looked into code you've linked and tried to prevent dind from mounting it, since I know that when I mount it myself, it just works. I got it working with this hackish mounting. Dunno how or why, but it just works:

"runArgs": ["-v", "/tmp:/tmp", "-v", "/tmp/.X11-unix:/tmp/.X11-unix"],

Now I can run playwright in GUI headed chrome (needs X11) and AWS sam local start-api (needs docker-in-docker - spins docker containers) inside devcontainer. That is my goal. I would use docker-FROM-docker, but can't get AWS sam local start-api work with that. I must wait untill aws will support running sam from container.

I do use Docker Desktop with WSL2, wslg and I'm pretty satisfied with running gui apps via X forwarding, no issues with slowiness, I'm running just browser so it shouldn't be extra demanding. The most important thing for me is, that it's one-liner -v /tmp/.X11-unix:/tmp/.X11-unix - boom gui works (sometimes not as in this case ^^). Thanks for your suggestion about desktop-lite fluxbox, but it seems pretty complex for setup to me in comparison with just forwarding X11 which I feel should be used for wslg?