End of support notice: On September 10, 2025, AWS
will discontinue support for AWS RoboMaker. After September 10, 2025, you will
no longer be able to access the AWS RoboMaker console or AWS RoboMaker resources.
For more information on transitioning to AWS Batch to help run containerized
simulations, visit this blog
post
Running a sample application with ROS 2 Foxy and Gazebo 11
The following tutorial shows you how to use container images to develop with ROS 2 Foxy and Gazebo 11, by creating and running the Hello World robot application and simulation application. You can get the sample application to work by running the commands described in this document.
For this tutorial, we create and use three container images. The following shows the directory structure that we use for this example application.
├── HelloWorldSampleAppROS2FoxyGazebo11 // Base Image │ └── Dockerfile ├── HelloWorldSampleAppROS2FoxyGazebo11RobotApp // Image for Robot App │ ├── Dockerfile │ └── robot-entrypoint.sh ├── HelloWorldSampleAppROS2FoxyGazebo11SimApp // Image for Simulation App │ ├── Dockerfile │ └── simulation-entrypoint.sh
Each Dockerfile has the instructions needed to build each image;
-
The Dockerfile for the base image has the commands to set up ROS and Gazebo.
-
The Dockerfile for the robot application has the commands to set up the Hello World robot application.
-
The Dockerfile for the simulation application has the commands to set up the Hello World simulation application.
Both the robot application and the simulation application have an entrypoint script. These scripts source the environments for their respective applications. They set up the path for you to run commands to start your robot and simulation applications.
Creating a base image
To create a base image, you save the commands to create your environment in a Dockerfile. You then build the Dockerfile.
-
Save the following commands in a Dockerfile.
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 FROM ros:foxy ENV DEBIAN_FRONTEND noninteractive RUN apt-get clean RUN apt-get update && apt-get install -y \ lsb \ unzip \ wget \ curl \ sudo \ python3-vcstool \ python3-rosinstall \ python3-colcon-common-extensions \ ros-foxy-rviz2 \ ros-foxy-rqt \ ros-foxy-rqt-common-plugins \ devilspie \ xfce4-terminal RUN wget https://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -; \ sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' RUN apt-get update && apt-get install -y gazebo11 ENV QT_X11_NO_MITSHM=1 ARG USERNAME=robomaker RUN groupadd $USERNAME RUN useradd -ms /bin/bash -g $USERNAME $USERNAME RUN sh -c 'echo "$USERNAME ALL=(root) NOPASSWD:ALL" >> /etc/sudoers' USER $USERNAME RUN sh -c 'cd /home/$USERNAME' # Download and build our Robot and Simulation application RUN sh -c 'mkdir -p /home/robomaker/workspace' RUN sh -c 'cd /home/robomaker/workspace && wget https://github.com/aws-robotics/aws-robomaker-sample-application-helloworld/archive/3527834.zip && unzip 3527834.zip && mv aws-robomaker-sample-application-helloworld-3527834771373beff0ed3630c13479567db4149e aws-robomaker-sample-application-helloworld-ros2' RUN sh -c 'cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros2' RUN sudo rosdep fix-permissions RUN rosdep update
After you've created the Dockerfile, build it using the following commands on your terminal.
cd ../HelloWorldSampleAppROS2FoxyGazebo11 docker build -t helloworldsampleappros2foxygazebo11:latest .
Building the base image installs ROS 2 Foxy and Gazebo 11. You need both libraries installed to successfully run your applications.
Creating an Image for the Robot Application
After you've created the base image, you can create the image for your robot application. You save the following script in a Dockerfile and build it. This script downloads the Hello World robot application and sets it up.
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 FROM helloworldsampleappros2foxygazebo11:latest # Build the Robot application RUN cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros2/robot_ws && \ /bin/bash -c "source /opt/ros/foxy/setup.bash && vcs import < .rosinstall && rosdep install --rosdistro foxy --from-paths src --ignore-src -r -y && colcon build" COPY robot-entrypoint.sh /home/robomaker/robot-entrypoint.sh RUN sh -c 'sudo chmod +x /home/robomaker/robot-entrypoint.sh' RUN sh -c 'sudo chown robomaker:robomaker /home/robomaker/robot-entrypoint.sh' CMD ros2 launch hello_world_robot rotate.launch.py ENTRYPOINT [ "/home/robomaker/robot-entrypoint.sh" ]
The following command creates the image for the robot application from the Dockerfile.
cd HelloWorldSampleAppROS2FoxyGazebo11RobotApp/HelloWorldSampleAppROS2FoxyGazebo11RobotApp docker build -t helloworldsampleappros2foxygazebo11robotapp:latest .
The following are the contents of the script that you can save as
robot-entrypoint.sh
. This script sources the environment for
the robot application.
#!/bin/bash if [ ! -z $GAZEBO_MASTER_URI ]; then tmp_GAZEBO_MASTER_URI=$GAZEBO_MASTER_URI fi cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros2/robot_ws source /opt/ros/foxy/setup.bash source /usr/share/gazebo-11/setup.sh source ./install/setup.sh if [ ! -z $tmp_GAZEBO_MASTER_URI ]; then export GAZEBO_MASTER_URI=$tmp_GAZEBO_MASTER_URI unset tmp_GAZEBO_MASTER_URI fi printenv exec "${@:1}"
Creating an image for the simulation application
After you've created the base image and the image for the robot application, you can create the image for your simulation application. You save the following script in a Dockerfile and build it. This script downloads the Hello World robot application and sets it up.
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 FROM helloworldsampleappros2foxygazebo11:latest # Build the Simulation application RUN cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros2/simulation_ws && \ /bin/bash -c "source /opt/ros/foxy/setup.bash && vcs import < .rosinstall && rosdep install --rosdistro foxy --from-paths src --ignore-src -r -y && colcon build" COPY simulation-entrypoint.sh /home/robomaker/simulation-entrypoint.sh RUN sh -c 'sudo chmod +x /home/robomaker/simulation-entrypoint.sh' RUN sh -c 'sudo chown robomaker:robomaker /home/robomaker/simulation-entrypoint.sh' CMD ros2 launch hello_world_simulation empty_world.launch.py ENTRYPOINT [ "/home/robomaker/simulation-entrypoint.sh" ]
The following command creates the image.
cd HelloWorldSampleAppROS2FoxyGazebo11SimApp/HelloWorldSampleAppROS2FoxyGazebo11SimApp docker build -t helloworldsampleappros2foxygazebo11simapp:latest .
The following are the contents of the script that you can save as
simulation-entrypoint.sh
. This script sources the environment
for the simulation application.
#!/bin/bash if [ ! -z $GAZEBO_MASTER_URI ]; then tmp_GAZEBO_MASTER_URI=$GAZEBO_MASTER_URI fi cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros2/simulation_ws source /opt/ros/foxy/setup.bash source /usr/share/gazebo-11/setup.sh source ./install/setup.sh if [ ! -z $tmp_GAZEBO_MASTER_URI ]; then export GAZEBO_MASTER_URI=$tmp_GAZEBO_MASTER_URI unset tmp_GAZEBO_MASTER_URI fi printenv exec "${@:1}"
Running the application and pushing it to Amazon ECR
After you've created your images, make sure that they run properly in your local Linux environment. After you've checked that your image runs, you can push your Docker image to Amazon ECR and create a simulation job.
The following commands give you the ability to run the Hello World application in your local Linux environment.
docker run -it -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ --name robot_app \ -u robomaker -e ROBOMAKER_GAZEBO_MASTER_URI=http://localhost:5555 \ -e ROBOMAKER_ROS_MASTER_URI=http://localhost:11311 \ helloworldsampleappros2foxygazebo11robotapp:latest
docker run -it -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ --name sim_app \ -u robomaker -e ROBOMAKER_GAZEBO_MASTER_URI=http://localhost:5555 \ -e ROBOMAKER_ROS_MASTER_URI=http://localhost:11311 \ helloworldsampleappros2foxygazebo11simapp:latest
When you run the robot application and simulation application containers, you can visualize the simulation using the Gazebo GUI tool. Use the following commands to:
-
Connect to your container running the simulation application.
-
Visualize your application by running the Gazebo Graphical User Interface (GUI).
# Enable access to X server to launch Gazebo from docker container $ xhost + # Check that the robot_app and sim_app containers are running. The command should list both containers $ docker container ls # Connect to the sim app container $ docker exec -it sim_app bash # Launch Gazebo from within the container $ /home/robomaker/simulation-entrypoint.sh ros2 launch gazebo_ros gzclient.launch.py
You can add tags to your images. The following commands give you the ability to tag your images.
docker tag helloworldsampleappros2foxygazebo11robotapp:latest
accountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleappros2foxygazebo11robotapp:latest
docker tag helloworldsampleappros2foxygazebo11simapp:latest
accountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleappros2foxygazebo11simapp:latest
After you've verified that the application is working properly, you can push to Amazon ECR using the following commands.
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin
accountID
.dkr.ecr.us-west-2.amazonaws.com docker pushaccountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleappros2foxygazebo11robotapp:latest docker pushaccountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleappros2foxygazebo11simapp:latest
You can then run a simulation job on the image. For more information about simulation jobs, see Simulation with AWS RoboMaker.