Robotics StackExchange | Archived questions

Package persistence in Dockerized ROS2 on RPi Buster 32 bit

I set up ROS2 Crystal in a Docker container on a Raspberry Pi 4b running 32 bit Buster (I need Buster to run for example OpenVINO and the NCS2 stick and an audio card). I used this to create the docker image:

https://github.com/surirohit/arm32v7-ros2-base

I set the image name to ros-docker

$ docker ps shows no containers running.

Starting the container:

pi@default-119:~/ros_docker $ docker
run -it ros-docker 
root@c777b2746004:~/ros2_ws# 
root@c777b2746004:~/ros2_ws# ls 
install  log  ros2.repos  src

and

pi@default-119:~/ros_docker $ docker
ps CONTAINER ID   IMAGE        COMMAND CREATED         STATUS         PORTS  NAMES 
c777b2746004   ros-docker   "/ros2_entrypoint.sh…"   3 minutes ago Up 3 minutes          zealous_banach

ros2_entrypoint.sh is this:

#!/bin/bash
set -e
export ROS2_DOMAIN_ID=1
source "$ROS2_WS/install/local_setup.bash"
exec "$@"

Looks good so far.

root@c777b2746004:~/ros2_ws# ls src
ament  eProsima  osrf  ros  ros-perception  ros-planning  ros-visualization  ros2

Now, when I create a package (the simple cpp pubsub):

root@c777b2746004:~/ros2_ws/src# ros2 pkg create --build-type ament_cmake cpp_pubsub
going to create a new package
package name: cpp_pubsub
destination directory: /root/ros2_ws/src
package format: 2
version: 0.0.0
description: TODO: Package description
maintainer: ['root <root@todo.todo>']
licenses: ['TODO: License declaration']
build type: ament_cmake
dependencies: []
creating folder ./cpp_pubsub
creating ./cpp_pubsub/package.xml
creating source and include folder
creating folder ./cpp_pubsub/src
creating folder ./cpp_pubsub/include/cpp_pubsub
creating ./cpp_pubsub/CMakeLists.txt

Then to confirm the creation:

root@c777b2746004:~/ros2_ws/src# ls
ament  cpp_pubsub  eProsima  osrf  ros  ros-perception  ros-planning  ros-visualization  ros2

Now when I stop the container (CTR-C and CTR-D) and restart the container:

pi@default-119:~/ros_docker $ docker run -it ros-docker
root@eb78a7379f7b:~/ros2_ws# ls src
ament  eProsima  osrf  ros  ros-perception  ros-planning  ros-visualization  ros2
root@eb78a7379f7b:~/ros2_ws# 

The cpp_pubsub package is no longer there.

Is it necessary to add a volume to the container to store newly created packages or am I missing something here?

Thanks,

Asked by mjohannessen on 2023-04-06 15:20:47 UTC

Comments

Answers

Now when I stop the container (CTR-C and CTR-D) and restart the container: [..] The cpp_pubsub package is no longer there.

This is really more of a Docker question than anything specific to ROS.

Technically that would make it off-topic here, but having written that: the package is "still there". The reason you're not seeing it in the ls output is you're not looking at the file system of the same container, as you're starting a new one the second time.

You can easily verify this by looking at the host part of the prompt inside the container:

  • first container: root@c777b2746004
  • second container: root@eb78a7379f7b

If you want to resume the container you started earlier, use docker start -ai <name_of_the_container> (zealous_banach in your example). It's nicer to give your containers recognisable names in these cases though. You can do that by adding --name=<desired_name_here> to your docker run command line.

Is it necessary to add a volume to the container to store newly created packages

it's not absolutely necessary, but if you'd like to be able to share workspaces between containers, or be able to access files you create inside a container from your host environment, then: yes, mounting volumes into containers would be a straightforward way to do this.

I set up ROS2 Crystal in a Docker container

just to draw attention to it: Crystal has been EOL since December 2019, so that's almost 4 years now. It's going to still contain issues fixed in more recent and still supported versions of ROS 2 and will likely offer a different UX in quite a few places (as some things just hadn't been implemented or finished yet back then).

Asked by gvdhoorn on 2023-04-07 01:41:43 UTC

Comments