Skip to content

tutorials vrx_docker_scripted

M1chaelM edited this page Mar 24, 2022 · 15 revisions

Option 2: Create a Dockerfile and entrypoint script

  • Run mkdir ~/my_vrx_docker; cd ~/my_vrx_docker

  • Run gedit Dockerfile and copy the following text into it:

# This is an auto generated Dockerfile for ros:ros-base
# generated from docker_images/create_ros_image.Dockerfile.em
FROM ros:noetic-ros-base

# install ros packages
RUN apt-get update && apt-get install -y \
    ros-noetic-ros-base \
&& rm -rf /var/lib/apt/lists/*

# Copy over script to Docker container
COPY ./run_my_system.bash /

# Use your ros_entrypoint
COPY ./ros_entrypoint.sh /
  • Run gedit run_my_system.sh to create your script. 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 /left_thrust_cmd std_msgs/Float32 -r ${RATE} -- ${CMD} &
rostopic pub /right_thrust_cmd std_msgs/Float32 -r ${RATE} -- ${CMD}

Then run chmod +x run_my_system.bash to make it executable.

  • Run gedit ros_entrypoint.sh to create your script. Copy the following text into the file
#!/bin/bash
set -e

# setup ros environment
source "/opt/ros/$ROS_DISTRO/setup.bash"

/run_my_system.bash

Then run chmod +x ros_entrypoint.sh to make it executable.

  • Run docker build --tag <USERNAME>/<IMAGE_REPOSITORY_NAME>:<TAG> . Eg. docker build --tag tylerlum/vrx-competitor-example:v2.2019 .

  • Run docker run <USERNAME>/<IMAGE_REPOSITORY_NAME>:<TAG> This will create a container with the image you created in the previous step, and then run /run_my_system.bash.

  • Run docker ps -a and take note of your container id. Then 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 to help you version your images. Example: docker commit -m "Start off ros-noetic-base, add run_my_system simple script" -a "Tyler Lum" a0e1e92cb6a5 tylerlum/vrx-competitor-example:v2.2019 or docker commit -m "Start off ros-noetic-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.

Clone this wiki locally