Fails to start devcontainer in VSCode due to lack of mounted device

eye-catch Docker

Even if I rebuilt and removed the image for devcontainer, it still failed to open it.

Sponsored links

Isn’t mounted device still used?

You can check the docker images created by vscode with the following command.

$ docker images | grep vs
vsc-play-with-go-lang-8588b89899858482bc1132acd213aa2c-uid       latest              dc8acaf39887   12 minutes ago   2.04GB
vsc-play-with-go-lang-8588b89899858482bc1132acd213aa2c           latest              3d1ed3fac40c   12 minutes ago   2.04GB
vsc-scanner-test-c96e911f3a02c07e7a78c14a73725296-features-uid   latest              7a387c6409e7   24 hours ago     1.88GB
vsc-scanner-test-c96e911f3a02c07e7a78c14a73725296-features       latest              fbbb9453ae80   8 days ago       1.88GB

Then remove

docker rmi -f vsc-play-with-go-lang-8588b89899858482bc1132acd213aa2c
docker rmi -f vsc-play-with-go-lang-8588b89899858482bc1132acd213aa2c-uid

But it still failed to open the container.

[2022-12-08T09:18:24.417Z] Dev Containers 0.266.1 in VS Code 1.73.1 (6261075646f055b99068d3688932416f2346dd3b).
[2022-12-08T09:18:24.417Z] Start: Resolving Remote
[2022-12-08T09:18:24.429Z] Setting up container for folder or workspace: /home/vagrant/development/my-application
[2022-12-08T09:18:24.434Z] Start: Check Docker is running
[2022-12-08T09:18:24.435Z] Start: Run: docker version --format {{.Server.APIVersion}}
[2022-12-08T09:18:24.537Z] Stop (102 ms): Run: docker version --format {{.Server.APIVersion}}
[2022-12-08T09:18:24.537Z] Server API version: 1.41
[2022-12-08T09:18:24.538Z] Stop (104 ms): Check Docker is running
[2022-12-08T09:18:24.538Z] Start: Run: docker volume ls -q
[2022-12-08T09:18:24.615Z] Stop (77 ms): Run: docker volume ls -q
[2022-12-08T09:18:24.627Z] Start: Run: docker ps -q -a --filter label=vsch.local.folder=/home/vagrant/development/my-application --filter label=vsch.quality=stable
[2022-12-08T09:18:24.725Z] Stop (98 ms): Run: docker ps -q -a --filter label=vsch.local.folder=/home/vagrant/development/my-application --filter label=vsch.quality=stable
[2022-12-08T09:18:24.726Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/vagrant/development/my-application
[2022-12-08T09:18:24.786Z] Stop (60 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/vagrant/development/my-application
[2022-12-08T09:18:24.786Z] Start: Run: docker inspect --type container e534dc1dbbb8
[2022-12-08T09:18:24.849Z] Stop (63 ms): Run: docker inspect --type container e534dc1dbbb8
[2022-12-08T09:18:24.850Z] Start: Run: /usr/share/code/code --ms-enable-electron-run-as-node /home/vagrant/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/vagrant/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --workspace-folder /home/vagrant/development/my-application --workspace-mount-consistency cached --id-label devcontainer.local_folder=/home/vagrant/development/my-application --log-level debug --log-format json --config /home/vagrant/development/my-application/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-12-08T09:18:25.112Z] (node:18871) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[2022-12-08T09:18:25.112Z] (Use `code --trace-deprecation ...` to show where the warning was created)
[2022-12-08T09:18:25.119Z] @devcontainers/cli 0.25.2. Node.js v16.14.2. linux 5.4.0-135-generic x64.
[2022-12-08T09:18:25.119Z] Start: Run: docker buildx version
[2022-12-08T09:18:25.304Z] Stop (185 ms): Run: docker buildx version
[2022-12-08T09:18:25.305Z] github.com/docker/buildx v0.7.1-docker 05846896d149da05f3d6fd1e7770da187b52a247
[2022-12-08T09:18:25.305Z] 
[2022-12-08T09:18:25.305Z] Start: Resolving Remote
[2022-12-08T09:18:25.309Z] Start: Run: git rev-parse --show-cdup
[2022-12-08T09:18:25.315Z] Stop (6 ms): Run: git rev-parse --show-cdup
[2022-12-08T09:18:25.317Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/vagrant/development/my-application
[2022-12-08T09:18:25.375Z] Stop (58 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/home/vagrant/development/my-application
[2022-12-08T09:18:25.376Z] Start: Run: docker inspect --type container e534dc1dbbb8
[2022-12-08T09:18:25.446Z] Stop (70 ms): Run: docker inspect --type container e534dc1dbbb8
[2022-12-08T09:18:25.447Z] Start: Starting container
[2022-12-08T09:18:25.447Z] Start: Run: docker start e534dc1dbbb8e214a215e0f895d3ecca7ab13619657904457cc1277a196c6320
[2022-12-08T09:18:25.613Z] Stop (166 ms): Run: docker start e534dc1dbbb8e214a215e0f895d3ecca7ab13619657904457cc1277a196c6320
[2022-12-08T09:18:25.623Z] Error: Command failed: docker start e534dc1dbbb8e214a215e0f895d3ecca7ab13619657904457cc1277a196c6320
[2022-12-08T09:18:25.623Z]     at Aoe (/home/vagrant/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js:1893:1355)
[2022-12-08T09:18:25.624Z]     at uT (/home/vagrant/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js:1893:1291)
[2022-12-08T09:18:25.624Z]     at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
[2022-12-08T09:18:25.624Z]     at async Poe (/home/vagrant/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js:1899:2128)
[2022-12-08T09:18:25.624Z]     at async Zf (/home/vagrant/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js:1899:3278)
[2022-12-08T09:18:25.624Z]     at async aue (/home/vagrant/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js:2020:15276)
[2022-12-08T09:18:25.624Z]     at async oue (/home/vagrant/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js:2020:15030)
[2022-12-08T09:18:25.628Z] Stop (778 ms): Run: /usr/share/code/code --ms-enable-electron-run-as-node /home/vagrant/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/vagrant/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --workspace-folder /home/vagrant/development/my-application --workspace-mount-consistency cached --id-label devcontainer.local_folder=/home/vagrant/development/my-application --log-level debug --log-format json --config /home/vagrant/development/my-application/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-12-08T09:18:25.629Z] Exit code 1
[2022-12-08T09:18:25.633Z] Command failed: /usr/share/code/code --ms-enable-electron-run-as-node /home/vagrant/.vscode/extensions/ms-vscode-remote.remote-containers-0.266.1/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/vagrant/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --workspace-folder /home/vagrant/development/my-application --workspace-mount-consistency cached --id-label devcontainer.local_folder=/home/vagrant/development/my-application --log-level debug --log-format json --config /home/vagrant/development/my-application/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-12-08T09:18:25.634Z] Exit code 1

I found the actual executed command in the error, so I tried to execute it.

$ docker start e534dc1dbbb8e214a215e0f895d3ecca7ab13619657904457cc1277a196c6320
Error response from daemon: error gathering device information while adding custom device "/dev/bus/usb/001/009": no such file or directory
Error: failed to start containers: e534dc1dbbb8e214a215e0f895d3ecca7ab13619657904457cc1277a196c6320

Oh my god. I mounted a device to the docker container like this.

{
    "name": "Go",
    "build": {
        "dockerfile": "Dockerfile"
    },
    "runArgs": [
        ...
        "--device=/dev/bus/usb/001/009"
    ],
    ...

However, the path changes after restart.

The image doesn’t exist anymore but it seems that vs code tries to start the container with the specified device that doesn’t exist anymore.

I removed the device attach option from the devcontainer.json but vscode still used the same container with the same option (with the device).

What I needed to do is to remove the container.

$ docker container rm e534dc1dbbb8e214a215e0f895d3ecca7ab13619657904457cc1277a196c6320

It took me more than 1 hour to find out this…

The error log should be carefully read.

Sponsored links

Container cannot be killed/removed

The target container could not be killed/removed.

$ docker container kill <your_container_id>
Error response from daemon: Cannot kill container: <your_container_id>: tried to kill container, but did not receive an exit event
vagrant@PFPC3522-cn-devvm:~/development$ docker container rm -f  <your_container_id>
Error response from daemon: Could not kill running container <your_container_id>, cannot remove - tried to kill container, but did not receive an exit event

I tried to restart the docker daemon but it still could not remove it!

$ sudo service docker restart
$ docker container rm -f <your_container_id>
Error response from daemon: removal of container <your_container_id> is already in progress

So I killed the process. Firstly, get the target PID of the docker container process.

$ ps -aux | grep <your_container_id>
root       54070  0.2  0.0 713104 10064 ?        Sl   10:23   0:16 /usr/bin/containerd-shim-runc-v2 -namespace moby -id <your_container_id> -address /run/containerd/containerd.sock
vagrant   117592  0.0  0.0   8160  2640 pts/1    R+   12:25   0:00 grep --color=auto <your_container_id>

The second column is the PID. Then, kill it with the following command.

# sudo kill -9 <your_PID>
sudo kill -9 54070

Docker keeps state “removal in progress”

Then, I tried to remove the container again but…

$ docker container rm f0d32f
Error response from daemon: removal of container f0d32f is already in progress

It keeps this state for a while.

So, I got the following error when I rebuilt the devcontainer again.

docker: Error response from daemon: Conflict. The container name "/my_dev" is already in use by container "". You have to remove (or rename) that container to be able to reuse that name.

According to this comment on GitHub issue, the directory needs to be removed.

sudo systemctl stop docker
sudo rm -rf /var/lib/docker/containers/<your_container_id>
sudo systemctl start docker

The Docker version discussed in the issue is 17.xx.yy but my Docker version is 20.10.12.

Comments

Copied title and URL