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 Melodic and Gazebo 9
The following tutorial shows you how to use container images to develop with ROS and Gazebo 9 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.
├── HelloWorldSampleAppROSMelodicGazebo9 // Base Image │ └── Dockerfile ├── HelloWorldSampleAppROSMelodicGazebo9RobotApp // Image for Robot App │ ├── Dockerfile │ └── robot-entrypoint.sh ├── HelloWorldSampleAppROSMelodicGazebo9SimApp // 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 entrypoint scripts. These scripts source the environments for their respective applications. They set up the path for you to run commands that give you the ability to run your robot and simulation applications.
Creating a base image
To create a base image, save the commands in the example to create your environment in a Dockerfile. 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:melodic ENV DEBIAN_FRONTEND noninteractive RUN apt-get clean RUN apt-get update && apt-get install -y \ lsb \ unzip \ wget \ curl \ sudo \ python-vcstool \ python-rosinstall \ python3-colcon-common-extensions \ ros-melodic-rviz \ ros-melodic-rqt \ ros-melodic-rqt-common-plugins \ devilspie \ xfce4-terminal \ ros-melodic-gazebo-ros-pkgs \ ros-melodic-gazebo-ros-control \ ros-melodic-turtlebot3 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/ros1.zip && unzip ros1.zip' RUN sh -c 'cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros1' RUN sudo rosdep fix-permissions RUN rosdep update
-
After you've created the Dockerfile, build it using the following commands on your terminal.
cd ../HelloWorldSampleAppROSMelodicGazebo9 docker build -t helloworldsampleapprosmelodicgazebo9:latest .
Building the base image installs ROS Melodic and Gazebo 9. You need both libraries installed to successfully run your applications.
Creating an image for the robot application
After you've created the base image, create the image for your robot application.
-
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 helloworldsampleapprosmelodicgazebo9:latest # Build the Robot application RUN cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros1/robot_ws && \ /bin/bash -c "source /opt/ros/melodic/setup.bash && vcs import < .rosinstall && rosdep install --rosdistro melodic --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 roslaunch hello_world_robot rotate.launch ENTRYPOINT [ "/home/robomaker/robot-entrypoint.sh" ]
-
Use the following command to create the image for the robot application from the Dockerfile.
cd HelloWorldSampleAppROSMelodicGazebo9RobotApp/HelloWorldSampleAppROSMelodicGazebo9RobotApp docker build -t helloworldsampleapprosmelodicgazebo9robotapp:latest image/.
-
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-ros1/robot_ws source /opt/ros/melodic/setup.bash source /usr/share/gazebo-9/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.
-
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 helloworldsampleapprosmelodicgazebo9:latest # Build the Simulation application RUN cd /home/robomaker/workspace/aws-robomaker-sample-application-helloworld-ros1/simulation_ws && \ /bin/bash -c "source /opt/ros/melodic/setup.bash && vcs import < .rosinstall && rosdep install --rosdistro melodic --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 roslaunch hello_world_simulation empty_world.launch ENTRYPOINT [ "/home/robomaker/simulation-entrypoint.sh" ]
-
Save the following
simulation-entrypoint.sh
script. 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-ros1/simulation_ws source /opt/ros/melodic/setup.bash source /usr/share/gazebo-9/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 ECR
After you've created your images, make sure that they run properly in your local Linux environment. After you've checked that Docker image runs, you can push it to Amazon ECR and create a simulation job.
-
Use the following commands to run the Hello World application in your local Linux environment.
docker run -it -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ \ -u robomaker -e ROBOMAKER_GAZEBO_MASTER_URI=http://localhost:5555 \ -e ROBOMAKER_ROS_MASTER_URI=http://localhost:11311 \ helloworldsampleapprosmelodicgazebo9robotapp:latest
docker run -it -e DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ \ -u robomaker -e ROBOMAKER_GAZEBO_MASTER_URI=http://localhost:5555 \ -e ROBOMAKER_ROS_MASTER_URI=http://localhost:11311 \ helloworldsampleapprosmelodicgazebo9simapp:latest
-
Run the robot application and simulation application containers to 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 $ rosrun gazebo_ros gzclient
-
-
Add tags to your images to keep them organized. Use the following commands to tag your images.
docker tag helloworldsampleapprosmelodicgazebo9robotapp:latest
accountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleapprosmelodicgazebo9robotapp:latestdocker tag helloworldsampleapprosmelodicgazebo9simapp:latest
accountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleapprosmelodicgazebo9simapp: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/helloworldsampleapprosmelodicgazebo9robotapp:latest docker pushaccountID
.dkr.ecr.us-west-2.amazonaws.com/helloworldsampleapprosmelodicgazebo9simapp:latest
You can then run a simulation job on the image. For more information about simulation jobs, see Simulation with AWS RoboMaker.