Skip to content

ROS2 Docker to WSL2

This guide outlines the procedure for exporting an existing ROS 2 Docker image (such as the PAL Public Docker or the PAL Development Docker and importing it into the Windows Subsystem for Linux (WSL2) for native use on a Windows host.

Prerequisites

Before beginning, ensure you have the following:

Step 1: Export the Docker Container

First, the Docker container must be exported into a .tar archive. To prevent the container from immediately exiting, run it with a continuous process:

docker run --name <container_name> <your_ros2_image> sleep infinity

Once the container is running, open a new terminal or use the existing one to export the container's filesystem:

docker export <container_name> -o <export_name>.tar

Note

This process generates a large file (e.g., public-simulation-humble-public.tar) and may take several minutes to complete depending on the image size.

Step 2: Import the Archive into WSL2

Open Windows PowerShell as an Administrator.

Before importing, you must create a dedicated directory on your host machine to store the WSL distribution's filesystem. WSL will not create this directory automatically, and failure to do so will result in a wsl/E_invalidarg error.

mkdir C:\Users\Username\Documents\<distribution_name>

Next, ensure the exported .tar file is accessible on your Windows machine. Run the following command to import the distribution, replacing the placeholder paths with your actual directories:

wsl --import <distribution_name> C:\Users\Username\Documents\<distribution_name> C:\path\to\<export_name>.tar

Troubleshooting: wsl/E_invalidarg Error

If you encounter an error during import, verify the following:

  • Target directory does not exist: Ensure you ran the mkdir command above.
  • Distribution name already in use: Check existing distributions via wsl --list. If a conflict exists, unregister the old instance using wsl --unregister <distribution_name> and try again.
  • Invalid file path: Confirm the .tar file exists at the specified location (verify using dir C:\path\to\<export_name>.tar).
  • Incorrect WSL version: Ensure WSL2 is configured as your default architecture by running wsl --set-default-version 2.

Step 3: Launch the WSL2 Distribution

Once the import is complete, you can launch your newly created WSL environment:

wsl -d <distribution_name>

Note

Alternatively, you can search for the distribution by name in the Windows Start menu and launch it directly.

Step 4: Configure the ROS 2 Environment

To ensure ROS 2 commands are available upon login, you must source the setup script. You can do this manually per session, or automate it by adding it to your .bashrc file.

Option A: Manual Sourcing (Per Session)

source /opt/ros/humble/setup.bash

Option B: Automatic Sourcing (Recommended)

echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc

Warning

Replace humble in the paths above with your specific ROS 2 distribution

Step 5: Verify the Installation

To confirm the migration was successful, open two separate terminal windows inside your WSL distribution.

Terminal 1: Launch the Simulation

ros2 launch tiago_pro_gazebo tiago_pro_gazebo.launch.py is_public_sim:=True

Terminal 2: Verify Active Topics

ros2 topic list