I have the following setup:
- Windows (Host) – running docker desktop
- WSL2 – /home/user/workspace/nxg contains my project files
- Vscode connected with a Devcontainer
Project directory with relevant docker files:
.
├── .devcontainer
│ ├── devcontainer.json
│ ├── docker-compose.yaml
│ └── Dockerfile
├── docker-compose.build.yaml
├── docker-compose.yaml
├── Dockerfile
├── .dockerignore
├── .env
├── .env.docker
├── .env.sample
└── .vscode
├── launch.json
└── tasks.json
devcontainer.json:
{
"dockerComposeFile": ["../docker-compose.yaml", "docker-compose.yaml"],
"service": "nxg",
"workspaceFolder": "/workspace-nxg",
"shutdownAction": "stopCompose",
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"esbenp.prettier-vscode",
"ms-vscode.vscode-typescript-next",
"dbaeumer.vscode-eslint"
]
}
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
"postCreateCommand": {
"chown .pnpm-store" : "sudo chown node /workspace-nxg-/.pnpm-store",
"chown node_modules": "sudo chown node /workspace-nxg-/node_modules"
}
}
When I start DD (Docker desktop) and then VSC (visual studio code) to load my project I see 3/3 containers running:
- dev container
- postgres container
- nats container
This works great, I can query these container with docker ps -a
and docker compose ls
and both the containers are listed and the merged compose file by the devcontainer plugged is listed.
The problem and question:
The problem and question now is that I have another set of the exact same containers living somewhere in WSL. If I start VSC without DD it still works, these containers are not visible with docker ps -a
and they’re always running the moment I start WSL.
In this situation where DD is not running here is the output of various commands:
On Windows:
C:UsersRohan>docker compose ls
NAME STATUS CONFIG FILES
C:UsersRohan>docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
On WSL:
➜ ~ docker compose ls
NAME STATUS CONFIG FILES
➜ ~ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
➜ ~ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
86ca41fac541 nxg_postgres "docker-entrypoint.s…" 24 hours ago Exited (137) 17 hours ago nxg-postgres-1
c5daa37c18a5 vsc-nxg-b04a8eb6a5643967ef9d6f249b515bf6a6b34dac403c5f6bdd4897ad7c3a9c67-uid "/bin/sh -c 'echo Co…" 24 hours ago Exited (137) 17 hours ago nxg-1
e722162a3b66 nats:2.10.12 "/nats-server --name…" 4 days ago Exited (1) 17 hours ago nxg-nats-main-1
➜ ~ ls -l $(which docker)
-rwxr-xr-x 1 root root 35939040 Oct 26 2023 /usr/bin/docker
➜ ~ ls -l $(which kubectl)
lrwxrwxrwx 1 root root 55 Jul 25 16:18 /usr/local/bin/kubectl -> /mnt/wsl/docker-desktop/cli-tools/usr/local/bin/kubectl
➜ ~ ls -l $(which dockerd)
-rwxr-xr-x 1 root root 93546720 Oct 26 2023 /usr/bin/dockerd
➜ ~ ls -l $(which containerd)
-rwxr-xr-x 1 root root 52632728 Sep 15 2023 /usr/bin/containerd
Inside the devcontainer:
node ➜ /workspace-nxg (master) $ docker compose ls
NAME STATUS CONFIG FILES
node ➜ /workspace-nxg (master) $ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
node ➜ /workspace-nxg (master) $ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
WSL pgrep:
➜ ~ pgrep -ax "docker"
2016 docker exec -i -u root fc27d0ab8cb33c55a21abe7091464e5a100df6cd164ecb6af24665b448e9bb95 /bin/sh -c echo "New container started. Keep-alive process started." ; export VSCODE_REMOTE_CONTAINERS_SESSION=38abadb3-e52c-42a3-b8a4-29b11bc302a91721385658625 ; /bin/sh
2039 docker exec -i -u node -e VSCODE_REMOTE_CONTAINERS_SESSION=38abadb3-e52c-42a3-b8a4-29b11bc302a91721385658625 fc27d0ab8cb33c55a21abe7091464e5a100df6cd164ecb6af24665b448e9bb95 /bin/sh
2131 docker exec -i -u root fc27d0ab8cb33c55a21abe7091464e5a100df6cd164ecb6af24665b448e9bb95 /bin/sh
2216 docker exec -i -u node fc27d0ab8cb33c55a21abe7091464e5a100df6cd164ecb6af24665b448e9bb95 /bin/sh
2391 docker exec -i -u node -e SHELL=/bin/bash -e VSCODE_AGENT_FOLDER=/home/node/.vscode-server -w /home/node/.vscode-server/bin/f1e16e1e6214d7c44d078b1f0607b2388f29d729 fc27d0ab8cb33c55a21abe7091464e5a100df6cd164ecb6af24665b448e9bb95 /home/node/.vscode-server/bin/f1e16e1e6214d7c44d078b1f0607b2388f29d729/bin/code-server --log debug --force-disable-user-env --server-data-dir /home/node/.vscode-server --use-host-proxy --telemetry-level all --accept-server-license-terms --host 127.0.0.1 --port 0 --connection-token-file /home/node/.vscode-server/data/Machine/.connection-token-f1e16e1e6214d7c44d078b1f0607b2388f29d729 --extensions-download-dir /home/node/.vscode-server/extensionsCache --install-extension ms-azuretools.vscode-docker --install-extension esbenp.prettier-vscode --install-extension ms-vscode.vscode-typescript-next --install-extension dbaeumer.vscode-eslint --start-server --disable-websocket-compression --skip-requirements-check
2466 docker exec -i -u node -e VSCODE_REMOTE_CONTAINERS_SESSION=38abadb3-e52c-42a3-b8a4-29b11bc302a91721385658625 fc27d0ab8cb33c55a21abe7091464e5a100df6cd164ecb6af24665b448e9bb95 /home/node/.vscode-server/bin/f1e16e1e6214d7c44d078b1f0607b2388f29d729/node -e const net = require('net'); const fs = require('fs'); process.stdin.pause(); const client = net.createConnection({ host: '127.0.0.1', port: 42707 }, () => { console.error('Connection established'); client.pipe(process.stdout); process.stdin.pipe(client); }); client.on('close', function (hadError) { console.error(hadError ? 'Remote close with error' : 'Remote close'); process.exit(hadError ? 1 : 0); }); client.on('error', function (err) { process.stderr.write(err && (err.stack || err.message) || String(err)); }); process.stdin.on('close', function (hadError) { console.error(hadError ? 'Remote stdin close with error' : 'Remote stdin close'); process.exit(hadError ? 1 : 0); }); process.on('uncaughtException', function (err) { fs.writeSync(process.stderr.fd, `Uncaught Exception: ${String(err && (err.stack || err.message) || err)}n`); });
2536 docker exec -i -u node -e VSCODE_REMOTE_CONTAINERS_SESSION=38abadb3-e52c-42a3-b8a4-29b11bc302a91721385658625 fc27d0ab8cb33c55a21abe7091464e5a100df6cd164ecb6af24665b448e9bb95 /home/node/.vscode-server/bin/f1e16e1e6214d7c44d078b1f0607b2388f29d729/node -e const net = require('net'); const fs = require('fs'); process.stdin.pause(); const client = net.createConnection({ host: '127.0.0.1', port: 42707 }, () => { console.error('Connection established'); client.pipe(process.stdout); process.stdin.pipe(client); }); client.on('close', function (hadError) { console.error(hadError ? 'Remote close with error' : 'Remote close'); process.exit(hadError ? 1 : 0); }); client.on('error', function (err) { process.stderr.write(err && (err.stack || err.message) || String(err)); }); process.stdin.on('close', function (hadError) { console.error(hadError ? 'Remote stdin close with error' : 'Remote stdin close'); process.exit(hadError ? 1 : 0); }); process.on('uncaughtException', function (err) { fs.writeSync(process.stderr.fd, `Uncaught Exception: ${String(err && (err.stack || err.message) || err)}n`); });
21866 docker events --since 1721391815 --until 1721392115 --filter type=container --filter type=image --filter type=network --filter type=volume --filter event=create --filter event=destroy --filter event=die --filter event=kill --filter event=pause --filter event=rename --filter event=restart --filter event=start --filter event=stop --filter event=unpause --filter event=update --filter event=delete --filter event=import --filter event=load --filter event=pull --filter event=save --filter event=tag --filter event=untag --filter event=remove --filter event=prune --format {{json .}}
➜ ~ pgrep -ax "containerd"
56 containerd --config /var/run/docker/containerd/containerd.toml
1930 containerd --config /var/run/docker/containerd/containerd.toml
➜ ~ pgrep -ax "dockerd"
24 /usr/bin/dockerd -p /var/run/docker.pid
1888 dockerd
WSL lsof:
# With containers active
➜ Rohan sudo lsof -i | grep "LISTEN"
[sudo] password for user:
docker-pr 646 root 4u IPv4 23613 0t0 TCP *:8222 (LISTEN)
docker-pr 653 root 4u IPv6 26845 0t0 TCP *:8222 (LISTEN)
docker-pr 669 root 4u IPv4 17628 0t0 TCP *:4222 (LISTEN)
docker-pr 675 root 4u IPv6 17631 0t0 TCP *:4222 (LISTEN)
docker-pr 757 root 4u IPv4 26901 0t0 TCP *:postgresql (LISTEN)
docker-pr 764 root 4u IPv6 18649 0t0 TCP *:postgresql (LISTEN)
#With DD containers shutdown(same result)
➜ Rohan sudo lsof -i | grep "LISTEN"
docker-pr 646 root 4u IPv4 23613 0t0 TCP *:8222 (LISTEN)
docker-pr 653 root 4u IPv6 26845 0t0 TCP *:8222 (LISTEN)
docker-pr 669 root 4u IPv4 17628 0t0 TCP *:4222 (LISTEN)
docker-pr 675 root 4u IPv6 17631 0t0 TCP *:4222 (LISTEN)
docker-pr 757 root 4u IPv4 26901 0t0 TCP *:postgresql (LISTEN)
docker-pr 764 root 4u IPv6 18649 0t0 TCP *:postgresql (LISTEN)
Please keep in mind that I have previously installed docker/k3s on WSL before I switched to DD so when cleaning WSL of the old docker I might have left some files. I feel like the devcontainers plugin has some kind of "backup" manner of managing containers but I don’t understand how to stop these containers and clean up their resources except for a killall
and then also prevent this "backup" method.
I assume there’s a service file somewhere that’s starting these containers that I could delete but all of these are not the source of the problems in my opinion.
Hopefully I’ve provided enough info, there’s logs I could add with and without DD of the devcontainer plugin but those contain sensitive information so I’d prefer to scrub them and upload them only if needed.
2
Answers
If DD is not running and you removed the docker engine installation from the WSL2 distro then you should not be able to issue docker commands at all so most probably you still have docker engine installed inside the WSL2 distro that you should get rid of (if your goal is to use DD only)
Is the docker command that’s being run in WSL actually going to linux, and not to windows? Or alternatively are you using the DD WSL2 backend?
What is the output of
whereis docker
in WSL?