Author: Tobit Flatscher (2024)
Docker can also be installed on Windows (with a WSL 2 backend) as is described in more detail here. After installing Docker you can use the docker
as well as docker compose
commands from within PowerShell. Currently this standard approach does not allow you though to stream graphic user interfaces to the host system while using WSL directly does.
Since Windows 10 Build 19044+ or Windows 11 (January 2024) Windows Subsystem for Linux 2 (WSL2) supports Linux GUI applications. This enables us to use Docker in the same way as we do on Ubuntu including our graphic user interfaces. If you want to check if your operating system supports it, check the version of your operating system as discussed here. Potentially you will have to follow the following steps to update (Windows 10 to the corresponding build version) or upgrade your operating system (to either Windows 10 or 11). The following paragraphs describe how your Windows 10 or 11 system can then be configured so that you can use graphic user interfaces in the same way as on a Ubuntu system.
As hardware (such as network interfaces) has to be shared between the Windows and the Linux subsystem WSL makes heavy use of virtualization that differs in between WSL and WSL 2 as discussed here. This can lead to problems with hardware such as e.g. here. This makes WSL not very favourable for development or deployment (for ROS 2 it might be better to install it on the host system directly as described here and run at least the nodes that interface the hardware on the operating system without a container). In my opinion the main use cases for Docker on Windows are therefore the following:
- Getting started with robotics: You do not have a Linux system but want to try ROS on your system. WSL allows you to work with ROS as well as ROS 2 at least in simulation.
- Data sharing: You might need to interact with clients, partner companies and share holders that are either not familiar with Linux or are not allowed to use Linux due to security restructions (most companies strangely enough still allow WSL to be used though). They can then either work in simulation or from recorded ROS bag data.
The following paragraph will quickly walk you through the installation of Windows Subsystem for Linux as well as the Windows Subsystem for Linux GUI (WSLg) extension. The basic steps are listed here but I will elaborate them in more detail. First of all follow the steps to install WSL as outlined here. This basically involves opening a PowerShell and either typing $ wsl --install
or
$ wsl --install -d Ubuntu
where the distribution Ubuntu
can be replaced by any of the choices given by $ wsl --list --online
.
If you already had WSL installed you might need to update it as follows:
$ wsl --update
$ wsl --shutdown
In the PowerShell check the version of WSL of your subsystem. There are two versions 1
and 2
which are different in a few relevant aspects (as discussed e.g. here). Make sure your subsystem is running version 2 and switch as follows if necessary:
$ wsl -l -v
NAME STATE VERSION
* Ubuntu Running 1
$ wsl —set-version Ubuntu 2
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Conversion in progress, this may take a few minutes...
The operation completed successfully.
You can then open the Windows Subsystem for Linux by searching for WSL or Ubuntu inside the installed programs and running it. This will open a terminal that can be used like any other Linux terminal.
Inside WSL check the DISPLAY
variable:
$ echo $DISPLAY
:0
It should be set to :0
. If it is not, make sure that you are using WSL 2 as discussed above and follow the debugging guide here.
Proceed to install and run any GUI-based program such as gedit
:
$ sudo apt install gedit
$ gedit
This should bring up the graphic user interface on your host system.
Make sure you have graphics drivers for your graphics card installed. This is not strictly necessary but is useful for hardware acceleration (e.g. OpenGL). The Nvidia drivers can be downloaded here by selecting your graphics card and the operating system. To see if the hardware acceleration is working in WSL, launch WSL and make sure that $ nvidia-smi
detects your graphics card.
Graphic user interfaces in WSL 2 then work in the very same way as on Linux operating systems. Follow the installation of Docker and Docker-Compose as discussed in Introduction.md
as well as the set-up for graphic user interfaces in Gui.md
, including the Nvidia container toolkit in case you want to run hardware acceleration. You can then use the regular docker
and docker compose
commands inside the WSL in combination with the templates found in templates/
.
In the figure below you can see the output of running the Affordance Templates workspace example on a Windows 10 operating system. For this purpose just clone this repository inside the subsystem for Linux
$ git clone https://github.com/2b-t/docker-for-robotics.git
$ cd docker-for-robotics/examples/affordance-templates-ros-docker
$ docker compose -f docker/docker-compose-gui.yml up
Then open another terminal and attach to the container with
$ docker exec -it affordance_templates bash
and there continue to build the workspace and run the main launch file of this example as discussed here.