# Trouble-Shooting Docker and Containers With Windows This document compiles some advice for dealing with common issues running docker and dev containers on Windows machines. If none of these things work, or you have a completely different problem getting the containers to work, please get in touch with the course organisers as soon as possible. ## Pre-requisite: WSL Docker requires you to have installed WSL (Windows Subsystem for Linux), specifically WSL2. You can type `wsl -l -v` into you terminal to see what you have, e.g. my terminal output is: ``` NAME STATE VERSION * Ubuntu Running 2 docker-desktop-data Running 2 docker-desktop Running 2 ``` If you haven't got WSL installed you can follow these instructions to get it: https://learn.microsoft.com/en-us/windows/wsl/install Don't forget the `wsl --set-default-version 2` step to make sure that you use WSL2 by default! ## Pre-requisite: Setting up VSCode You should install the [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension. It is also a good idea to install the [Remote Development](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) extension pack (which includes the WSL extension for VSCode) as this will allow you to develop on your linux environment if necessary. ## Pre-requisite: Install Docker on Windows If you haven't already, download [Docker Desktop](https://www.docker.com/products/docker-desktop/) for Windows and install with [these instructions](https://docs.docker.com/desktop/install/windows-install/). ## Problem: VSCode doesn't find the .devcontainer The `.devcontainer` folder can be found in [this repository](https://github.com/UCL/rc-cpp-vscode-dev-container/tree/dab11e45f5364cd9134aade9a0aff92a35d1837f). It needs to be present at the top level of any folder that you want to open in the container. If you're trying this in the week 1 exercises folder: - First delete the `.devcontainer` sym-link, as this will not be recognised on windows. - Then copy the `.devcontainer` folder from the repo into your folder. - Re-open the folder with VSCode. It should now ask if you want to re-open in a container. If not, click the green double arrow in the bottom left hand corner and select "Re-open in container" from the menu. ## Problem: VSCode finds the container but the build fails This may be because of conflicts between the way that UNIX and Windows handle line endings in files. You may see `'bash\r': No such file or directory` somewhere in your error output. In this case, the easiest thing to do is to delete the repo and then use the command: `git config --global core.autocrlf false` This will tell git _not_ to automatically convert the linux style files on the repo to windows style files. Clone the repo again, and copy the `.devcontainer` folder into the folder that you want to open in the container. Then try opening the folder in VSCode and building the container. Don't forget to reset `git config --global core.autocrlf true` when you're done. You can find [more information on line endings and git here](https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings). ## Problem: Docker is installed and running but I still can't use the container in VSCode Try using WSL in VSCode. Open a new VSCode window, click the double arrow in the bottom left hand corner, and select, "New WSL Window" to open VSCode inside WSL. Alternatively, you can open a command prompt and type `wsl` to launch WSL, and then type `code .` to launch VSCode from inside WSL. It may take a little time to set up. Inside WSL, either in the VSCode terminal or in a separate command prompt, clone the repo directly into your linux subsystem. (No need to worry about git line ending conversions here since we are using Linux!) Check that the Dev Containers extension is available in VSCode inside WSL (it is possible to install an extension only in Windows, only in WSL, or globally). If it is not installed, install it. Make sure the `.devcontainer` folder exists and is copied into the folder you want to open in the container. Open the folder in VSCode and then re-open in the container. ## Problem: Docker Daemon service can't be found / isn't responsive Go the Services app in Windows and check through the list to see if Docker Desktop Service is running. If not, try updating your WSL installation, and then re-starting Docker. If it is running correctly you should be able to see it in the Services app and typing the following command in the terminal should work: `docker run hello-world`. There is a [detailed walkthrough here](https://linuxhint.com/resolve-docker-daemon-not-running/). ## Problem: Docker is still not working on my machine, or Docker Desktop is hanging forever Try uninstalling Docker Desktop and installing docker directly onto WSL. If you don't already have it, install [Ubuntu for WSL](https://ubuntu.com/wsl). [This article](https://dev.to/bowmanjd/install-docker-on-windows-wsl-without-docker-desktop-34m9) contains advice on installing docker inside WSL. It is very similar to the regular Linux install, except that you will need to do one or two additional things manually. Once you have docker running and can run the `docker run hello-world` command successfully, you can clone the repo (inside WSL) and open it in VSCode. Remember the `.devcontainer` folder needs to be present for you to open a folder in a container. ## Problem: None of these work! Please get in touch and let us know, or book some time using the office hours.