Run a single ROS node inside a Docker container

This is a follow up question to this question.

I want to build docker images, each running only a single node from a given package. To achieve this I see 3 possibilities:

  1. Copy the entire package into the docker images but replace the roslaunch with rosrun target_package target_node.
  2. Create an individual package for each single node.
  3. Isolate the built executeable and it’s dependencies for each individual node.

The first one is easy to do but somewhat dirty. The second one seems to be extremely tedious. If possible I’d like to create a script that does what’s needed to get the 3rd option, but I am not sure if that’s doable/intended and if it’s even at all better than the first option.

Source: StackOverflow