-
Notifications
You must be signed in to change notification settings - Fork 243
tutorials vrx_docker_interactive
-
Run
docker run --name my_container -it ros:noetic-ros-base. This will pull theros:noetic-ros-baseimage from DockerHub and create a container of that image calledmy_container.-it` is added so that when this is complete, it starts an interactive Bash session for you to run commands. This may take a few minutes to run. -
This Bash session is very barebones. It does not have a text editor yet, so we will install one now. From the created interactive Bash session, run
apt-get update && apt-get install -y nanoor replacenanowith your text editor of choice. -
Use the text editor to edit
ros_entrypoint.sh. Eg.nano /ros_entrypoint.sh. This is a script that is run immediately after your container has been built. Replace all the text with the following:
#!/bin/bash
set -e
# setup ros environment
source "/opt/ros/$ROS_DISTRO/setup.bash"
/run_my_system.bash
This will run the script run_my_system.bash.
- Create the
run_my_system.bashscript.nano /run_my_system.bash. Copy the following text into the file
#!/bin/bash
# Create ros master if not already started
rostopic list > /dev/null 2>&1
retVal=$?
if [ $retVal -ne 0 ]; then
roscore &
echo "Wait for 5s to allow rosmaster to start"
sleep 5s
else
echo "rosmaster already setup"
fi
# Send forward command
RATE=1
CMD=2
echo "Sending forward command"
rostopic pub /wamv/thrusters/left_thrust_cmd std_msgs/Float32 -r ${RATE} -- ${CMD} &
rostopic pub /wamv/thrusters/right_thrust_cmd std_msgs/Float32 -r ${RATE} -- ${CMD}
-
Run
chmod +x /run_my_system.bashto make it executable. -
Run
/run_my_system.bash &to execute the script in the background. You should see the ros core service start up, and the output of the echo message, "Sending forward command data", from the script you just created. -
Hit enter to get back to a command prompt and run
rostopic echo /wamv/thrusters/left_thrust_cmdto test that your script is publishing data as expected. You should receive/wamv/thrusters/left_thrust_cmddata (which is set to 2.0 in the script). -
Run
exitto leave this container. -
Run
docker ps -ato list all containers. You should see your containermy_container. -
Copy the Container ID of
my_container. -
Run
docker commit -m "Start off ros-noetic-base, add run_my_system simple script" -a "<FULL NAME>" <Container_ID> <USERNAME>/<IMAGE_REPOSITORY_NAME>:<TAG>. Your username must match the username of your Dockerhub account. The image repository name is the repository name that the image will be saved to on Dockerhub. The tag and colon are optional (but highly recommended) to help you version your images. Example:docker commit -m "Start off ros-melodic-base, add run_my_system simple script" -a "Tyler Lum" a0e1e92cb6a5 tylerlum/vrx-competitor-example:v2.2019ordocker commit -m "Start off ros-melodic-base, add run_my_system simple script" -a "Tyler Lum" a0e1e92cb6a5 tylerlum/vrx-competitor-example -
Run
docker login -
Run
docker push <USERNAME>/<IMAGE_REPOSITORY_NAME>:<TAG>with the same information as the previous step. Eg.docker push tylerlum/vrx-competitor-example:v2.2019 -
You should be able to log onto your Dockerhub account and see your new repository.
-
Optional: If you want to keep your repository private, you can click on your repository, then click Settings, then Make Private. To ensure that your Docker image can be evaluated, you can click Collaborators and add the desired Docker ID. Exact details about submission and Docker ID are coming soon.