title: Run custom python code on ROS docker container
body: <p>I'm beginner with ROS, and I'm trying to run some listener/talker node running a really simple code in python, using ROS on a Docker container.</p>
  <p>I'm following the guide described in:
  <a href="https://hub.docker.com/_/ros" rel="nofollow noreferrer">https://hub.docker.com/_/ros</a></p>
  <p>I got this structure:</p>
  <pre><code>./
      Dockerfile
      docker-compose.yml
      ./teste/
              listener.py
  </code></pre>
  <p>My current goal is to pass the listener.py code and run in a &quot;listener&quot; node, running as a service container.</p>
  <p>My Dockerfile is:</p>
  <pre><code>FROM ros:foxy        
   # install ros package 
      RUN apt-get update &amp;&amp; apt-get install -y \
                ros-${ROS_DISTRO}-demo-nodes-cpp \
                ros-${ROS_DISTRO}-demo-nodes-py &amp;&amp; \
              rm -rf /var/lib/apt/lists/*
          
  # launch ros package
  
  CMD [&quot;ros2&quot;, &quot;launch&quot;, &quot;demo_nodes_cpp&quot;, &quot;talker_listener.launch.py&quot;]
  </code></pre>
  <p>My docker-compose.yml file is:</p>
  <pre><code>version: '3'
  
  services:
    talker:
      build: ./
      command: ros2 run demo_nodes_py talker
  
    listener:
      build: ./
      environment:
        - &quot;PYTHONUNBUFFERED=1&quot;
      volumes:
        - ./teste:/teste
      command: ros2 run demo_nodes_py listener
  
  volumes:
    teste:
  </code></pre>
  <p>With this default code, the two services runs the listener/talker from the original ros examples, but i want to run my own python code. How do i do that? Even that the listener service can access listener.py code (via ./teste) if i open an shell and try to execute it, the ros2 run command is not recognized.</p>
  <p>What am i doing wrong? Am i supposed to do something before to make my python code work on ros2? Any ideas?</p>
  <p>Thanks!</p>
  <p>Edit: ros2 command is not recognized if i open a shell terminal, but the by the cmd command on the Dockerfile, with the talker_listener.launch.py code, it works.</p>
  <p>Edit2: i managed to run the setup.sh via &quot;/bin/bash source /opt/ros/foxy/setup.bash&quot;. Even so, i can't run the ros2 commands. I used &quot;python3 /teste/listener.py&quot;, but then i got the error:</p>
  <pre><code>ModuleNotFoundError: No module named 'rospy'
  </code></pre>
  <p>How is that possible, if when i run the default command option (ros2 run demo_nodes_py listener, via Dockerfile) and it works?</p>