Skip to content

Instantly share code, notes, and snippets.

@tdamsma
Last active October 25, 2024 23:52
Show Gist options
  • Save tdamsma/06cafea175d6784aea7b3634bb9495c8 to your computer and use it in GitHub Desktop.
Save tdamsma/06cafea175d6784aea7b3634bb9495c8 to your computer and use it in GitHub Desktop.
Running VSCode remote containers on windows without docker desktop

Running VSCode remote containers on windows without docker desktop

Due to the license issues with docker desktop and the fact that you don't really need this buggy bit of software, this guide will walk you through the steps to use VSCode+remote-containers in combination with WSL2 without using docker desktop.

Get rid of docker desktop

Only if you have docker desktop currently installed of course

Uninstall docker desktop application

Via app & features in the windows settings menu

Remove WSL2 environments created by docker

in windows cmd.exe:

wsl --unregister docker-desktop-data
wsl --unregister docker-desktop

Remove docker settings from WSL

If you were using the docker CLI in WSL2 that came with Docker Desktp let's get rid of all traces of that

rm -rf ~/.docker
sudo rm -rf /usr/local/lib/docker

Set up docker + compose in WSL2

Install docker-ce

In theory you should also be able to sunstitute docker with podman, but I haven't tried that. Here are the instructions for using docker-ce, based roughly on this guide: https://docs.docker.com/engine/install/ubuntu/

Add the docker package registry with pre-built binaries

sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
   "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install docker deamon and CLI

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Add a groupp docker and add yourself so you can run docker without sudo:

sudo groupadd docker
sudo gpasswd -a $USER docker

Install docker compose and buildkit

Base on https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-compose-on-ubuntu-20-04 To be hones I am a bit lost as what goes where exacly, so will accpet suggestions/improvements. This is what worked for me.

# create directory for plugins
mkdir $HOME/.docker
mkdir $HOME/.docker/cli-plugins

# install docker-compose v2.2.3, see https://github.com/docker/compose/releases for latest
sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

# create symbolic link in plugins directory
ln -s /usr/local/bin/docker-compose $HOME/.docker/cli-plugins/docker-compose

# install buildx v0.7.1, see https://github.com/docker/buildx/releases for latest
sudo curl -L "https://github.com/docker/buildx/releases/download/v0.7.1/buildx-v0.7.1.linux-amd64" -o $HOME/.docker/cli-plugins/docker-buildx
sudo chmod +x $HOME/.docker/cli-plugins/docker-buildx

Start docker deamon on startup

There are multiple ways to accomplish this, see also:

I tried this and it sems to work adequately. Note that I user ZSH as terminal, if you use bash, you will need to modify .bashrc instead of .zshrc

Based on https://blog.nillsf.com/index.php/2020/06/29/how-to-automatically-start-the-docker-daemon-on-wsl2/

# Allow docker to be started without requesting sudo password:
sudo visudo
# add line 
<your user name> ALL=(ALL) NOPASSWD: /usr/bin/dockerd

# add docker stuff to ~/.zshrc
echo '# Start Docker daemon automatically when logging in if not running.' >> ~/.zshrc
echo 'RUNNING=`ps aux | grep dockerd | grep -v grep`' >> ~/.zshrc
echo 'if [ -z "$RUNNING" ]; then' >> ~/.zshrc
echo '    sudo dockerd > /dev/null 2>&1 &' >> ~/.zshrc
echo '    disown' >> ~/.zshrc
echo 'fi' >> ~/.zshrc

After this, finally docker should work, you can check with this test image

>> sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:975f4b14f326b05db86e16de00144f9c12257553bba9484fed41f9b6f2257800
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
...

[Optional] Enable docker buildkit

To enable docker buildkit you need to set DOCKER_BUILDKIT=1. However if you set that in ~/.zshrc this doesn't get loaded when VSCode calls docker. So we use the WSLENV variable like so:

  • Add DOCKER_BUILDKIT=1 to your windows environmental variables
  • set/append DOCKER_BUILDKIT/u: to the WSLENV variable Now every WSL instance will have the DOCKER_BUILDKIT variable set

Finally

[Optional] log into private container registries

From WSL2, log into docker

echo $CONTAINER_REGISTRY_PASSWORD | docker login -u $CONTAINER_REGISTRY_USERNAME --password-stdin  $CONTAINER_REGISTRY

Allow vscode to locate docker and docker compose

Make sure you have these extensions installed in vscode:

  • ms-vscode-remote.remote-wsl
  • ms-vscode-remote.remote-containers

Open WSL, and open vscode from there (use code . to open vscode in the current folder). In the lower left corner it should say WSL, to indicate that WSL is running from inside your WSL environment.

Troubleshooting

If you get an error message like Docker returned an error code ENOENT, message: ... you have most likely tried to open a folder on your windows drive in containers. With docker desktop this is possbile (but a bad idea giving bad performance), but with this setup it is not possible as there is not docker client installed in Windows, and that is how we want it. Make sure to move your projects to the wsl dirve (accessible as \\wsl$\Ubuntu\home from windows)

@zenithbb
Copy link

thanks for the detail explain

After installation, I can make docker-compose up and ran, mount host folders no issue, run terminal and script within docker has no issue, but can not use : "Attach Visual Studio Code", message: "cannot attache to the container with name/id/python, it no longer exists"
any help is welcome

@KonanTheLibrarian
Copy link

June 2023. Whole universities ALL getting rid of Docker Desktop as "MALWARE" and "Swamp of Bugs"

Totally agree, and Docker Desktop adds nothing that is not there already part of VSCODE and vanilla robust Docker.

Run VSCODE with Docker and WITHOUT Docker Desktop, sadly VSCODE 1.79.0 is totally broken with regard to WSL2 failing to connect to the network especially when developers are using IPsec level VPNs (which is most VPNs including in large corporations paying millions to Microsoft). The main link for running VS CODE WSL2 without Docker Desktop is https://nickjanetakis.com/blog/install-docker-in-wsl-2-without-docker-desktop yes and no kidding the long knives are out on "geniuses" closing bugs to make them "fixed without actually fixing anything".

  • Please associate bug reports and NOT close them, simply ADD links to bug reports to OTHERS that are same or similar, NEVER CLOSE BUGS that are associated with bug OTHER bug reports that are the same and are NOT closed. AS YOU ARE LOSING ACCUMULATED KNOWLEGE!

  • Staff CLOSING HUNDREDS OF CRITICAL VSCODE WSL2 or Docker BUGS WITHOUT ASSOCIATING THEM WITH HUNDREDS OF THE SAME BUGS (ALSO CLOSED) are geniuses that fix bugs by MAGIC!

VSCODE / VS Code version 1.79.0 network IP address integration totally BROKEN AS A BAD MESS including without Docker Desktop!

Pushing VSCODE insiders to release (VS Code version 1.79.0 on 9th June 2023) has caused a nuke level break event!

  • Please associate bug reports and NOT close them, simply ADD links to bug reports to OTHERS that are same or similar, NEVER CLOSE BUGS that are associated with bug OTHER bug reports that are the same and are NOT closed. WOULD YOU BE SUPPRISED IF ASKED TO PACK YOUR BOXES?

VSCODE or VS Code v1.79.0 must not be used with or without Docker Desktop (please disable auto upgrade) ping fails in WSL2 terminals

VSCode version 1.79.0 is totally a rotten as WSL2 networking fails, WSL2 IP TCP/IP and ping fails AND geniuses in the VSCODE team CLOSES hundreds of the same bug reports mentioning this SAME BUG WITHOUT FIXING IT!

Bug reports in "VSCODE insiders" with EXACTLY the same broken network (6 months prior) also CLOSED by "geniuses"

Closing bugs as a way to IGNORE the bugs. Note that the words GENIUSES above are replaced by the words meaning the exact opposite!

Their excuse: "We are closing this report to focus on more important issues." GENIUS!

  • Please associate bug reports and NOT close them, simply ADD links to bug reports to OTHERS that are same or similar, NEVER CLOSE BUGS that are associated with bug OTHER bug reports that are the same and are NOT closed. AS YOU LOSE ACCUMULATED KNOWLEGE! ARE YOU AN OSTRECH WITH ITS HEAD IN THE SAND?

  • Staff CLOSING HUNDREDS OF CRITICAL VSCODE WSL2 or Docker BUGS WITHOUT ASSOCIATING THEM WITH HUNDREDS OF THE SAME BUGS (ALSO CLOSED) are geniuses that fix bugs by MAGIC! I have seen of forums for Docker where developers have become angry. These CLOSED BUGS are so bad that this has to happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment