Skip to content

Efficient Docker Management for Robotics

Introduction

Docker is an essential tool for robotics development, offering quick prototyping, environment isolation, and streamlined deployment. However, managing containers effectively—especially with ROS (Robot Operating System)—can be complex. This guide highlights best practices for saving Docker images, removing unused resources, enabling GUI and Bluetooth in containers, and ensuring seamless ROS integration for robotics projects.


Key Topics Covered

  • Saving and tagging Docker images for reproducibility
  • Cleaning up unused images and resources
  • Running Docker containers with GUI and peripheral support
  • Setting up ROS workspaces inside containers
  • Debugging common integration issues

1. Saving Docker Containers as Images

Why Save Docker Containers?

  • Preserve your work after container modifications.
  • Quickly replicate development environments for prototyping or deployment.

Steps to Save an Image:

  1. Stop the container:

    sudo docker stop <container_name>
    

  2. Commit the container to an image:

    sudo docker commit <container_id> <new_image_name>
    

  3. Verify the saved image:

    sudo docker images
    

Example:

sudo docker commit 96a9ad78d1e6 roboclaw_v02


2. Removing Unused Images and Containers

Why Clean Up?

  • Free up disk space.
  • Reduce clutter from unused or dangling images.

Commands:

  1. List dangling images:

    sudo docker images -f dangling=true
    

  2. Remove dangling images:

    sudo docker image prune -f
    

  3. Remove specific images:

    sudo docker rmi <image_id>
    

  4. Remove stopped containers:

    sudo docker container prune
    


3. Running Containers with GUI and Peripheral Support

Why Enable GUI and Peripherals?

Robotics projects often require visualization tools like RViz and peripheral support for devices such as Xbox controllers or Bluetooth sensors. Docker flags ensure seamless integration.

Command Example:

sudo docker run -it --name roboclaw_v02 \
    --net=host \
    --privileged \
    --device=/dev/input/js0:/dev/input/js0 \
    --device=/dev/input/event0:/dev/input/event0 \
    -v /var/run/dbus:/var/run/dbus \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -e DISPLAY=$DISPLAY \
    roboclaw_v02

Explanation of Flags:

  • --net=host: Enables network communication between container and host.
  • --privileged: Grants access to host devices (e.g., Bluetooth).
  • --device: Maps input devices for peripherals like controllers.
  • -v: Mounts directories for GUI and device access.

4. Setting Up a ROS Workspace in Docker

Why Use a Mounted Workspace?

  • Edit code on the host machine while executing it inside the container.
  • Persist changes across container restarts.

Steps:

  1. Run the container with a mounted workspace:

    sudo docker run -it --name <container_name> \
        -v ~/ros_ws:/root/ros_ws \
        <base_image>
    

  2. Inside the container, initialize the ROS workspace:

    cd ~/ros_ws
    catkin_make
    source devel/setup.bash
    


5. Running ROS Nodes and Debugging

Starting roscore:

  1. Attach to the container:

    sudo docker exec -it <container_name> /bin/bash
    

  2. Start roscore:

    roscore
    

Running ROS Nodes:

  1. Source the workspace:

    source ~/ros_ws/devel/setup.bash
    

  2. Run the node:

    rosrun roboclaw_node xbox_teleop_odom.py
    


6. Debugging Common Issues

Issue: "Master Not Found"

  • Ensure roscore is running in the same container.

Issue: "Device Not Found"

  • Verify input device mapping:
    ls /dev/input/js0
    

Issue: "ROS_PACKAGE_PATH Missing"

  • Set the workspace path:
    export ROS_PACKAGE_PATH=/root/ros_ws/src:$ROS_PACKAGE_PATH
    

Conclusion

By mastering these Docker and ROS workflows, you can create efficient and portable robotics development environments. Whether it’s saving images, enabling peripherals, or debugging nodes, these practices ensure a robust foundation for prototyping and deployment.

Stay innovative, and build the future of robotics with confidence! 🚀


Created 2025-01-27, Updated 2025-01-27
Authors: Harminder Singh Nijjar (1)

Comments