A simple Docker setup for running ROS Noetic tutorials with a basic publisher/subscriber example using Python scripts.
.
├── Dockerfile
├── docker-compose.yml
├── README.md
└── catkin_ws/
└── src/
└── rospy_tutorials/
├── CMakeLists.txt
├── package.xml
├── scripts/
│ ├── listener.py
│ └── talker.py
└── src/
- Dockerfile: Simplified ROS Noetic container setup
- docker-compose.yml: Container orchestration configuration
- rospy_tutorials package: Contains the classic ROS tutorial scripts
talker.py: Publisher node that sends "hello world" messageslistener.py: Subscriber node that receives and logs messages
- Docker installed on your system
- Docker Compose installed on your system
# Build and start the container in detached mode
docker compose up -d --buildThis will:
- Build the Docker image with ROS Noetic and your catkin workspace
- Start the container named
ros-tutorials - Run in the background (detached mode)
You'll need three separate terminal windows/tabs for this demo.
# Connect to the container
docker exec -it ros-tutorials /bin/bash
# Start the ROS master node
roscoreKeep this terminal running. You should see:
... logging to /root/.ros/log/...
... started core service [/rosout]
Open a new terminal window/tab:
# Connect to the container in a new session
docker exec -it ros-tutorials /bin/bash
# Run the listener script
rosrun rospy_tutorials listener.pyThe listener is now waiting for messages. You should see a blank terminal waiting for a response from the Talker Node.
Open a third terminal window/tab:
# Connect to the container in a new session
docker exec -it ros-tutorials /bin/bash
# Run the talker script
rosrun rospy_tutorials talker.pyYou should now see:
- Terminal 3 (talker): Publishing "hello world" messages
- Terminal 2 (listener): Receiving and displaying those messages
Terminal 3 (Talker):
[INFO] [1634567890.123]: hello world 1634567890.12
[INFO] [1634567890.223]: hello world 1634567890.22
[INFO] [1634567890.323]: hello world 1634567890.32
Terminal 2 (Listener):
[INFO] [1634567890.124]: /listener_1634567890_123 I heard hello world 1634567890.12
[INFO] [1634567890.224]: /listener_1634567890_123 I heard hello world 1634567890.22
[INFO] [1634567890.324]: /listener_1634567890_123 I heard hello world 1634567890.32
In each terminal (in reverse order):
- Terminal 3 (talker): Press
Ctrl+Cto stop the talker node - Terminal 2 (listener): Press
Ctrl+Cto stop the listener node - Terminal 1 (roscore): Press
Ctrl+Cto stop roscore
In each terminal:
# Exit the container bash session
exit# Stop and remove the container, networks, and orphaned containers
docker compose down --remove-orphans --rmi allIf you want to modify the Python scripts without rebuilding the container, uncomment the volumes section in docker-compose.yml:
volumes:
- ./catkin_ws:/catkin_wsThen restart the container:
docker-compose down
docker-compose up -d# View running containers
docker ps
# View container logs
docker-compose logs
# View real-time logs
docker-compose logs -fInstead of interactive terminals, you can run commands directly:
# Start roscore in background
docker exec -d ros-tutorials bash -c "source /opt/ros/noetic/setup.bash && source /catkin_ws/devel/setup.bash && roscore"
# Run listener in background
docker exec -d ros-tutorials bash -c "source /opt/ros/noetic/setup.bash && source /catkin_ws/devel/setup.bash && rosrun rospy_tutorials listener.py"
# Run talker interactively
docker exec -it ros-tutorials bash -c "source /opt/ros/noetic/setup.bash && source /catkin_ws/devel/setup.bash && rosrun rospy_tutorials talker.py"# Check container status
docker-compose ps
# View detailed logs
docker-compose logs ros-tutorials- Ensure all three terminals are connected to the same container
- Verify roscore is running in Terminal 1 before starting other nodes
- Check that the container is using
network_mode: host
# If scripts aren't executable, fix permissions
docker exec -it ros-tutorials chmod +x /catkin_ws/src/rospy_tutorials/scripts/*.py- Modify the Python scripts to experiment with different message types
- Add more ROS nodes to the package
- Try connecting to external ROS masters by modifying
ROS_MASTER_URI - Explore ROS topics with
rostopic listandrostopic echo /chatter