简体   繁体   中英

What is the best practice to start "roscore" followed by "rosrun ...." on Docker Container startup?

I have created through a Dockerfile a Docker image on which Ubuntu 18.04 and ROS Melodic are properly installed. Please note that I have not used the official ROS-Docker image for creating my Docker image.

The Docker container derived from this Docker image is working fine. However, every time I want to work with the container, I need to execute the following commands:

  1. Terminal window:

docker run -d -it --name container_name docker_image; docker exec -it container_name bash

Then, after I am within the Docker container: roscore

  1. Terminal window:

docker exec -it container_name bash

Then, after I am within the Docker container: rosrun ROS_PackageName PythonScript.py

Please note that through the above-mentioned Docker commands, both terminals operate in the same Docker container.

I find my way to start the PythonScript.py inefficient. Therefore, I would like to ask for the best practice to start "roscore" followed by "rosrun...." on Docker Container startup.

In some Dockerfiles I see at the end of the file the command ENTRYPOINT as well as CMD . However, I do not know if these commands can help me to make my Docker container execute "roscore" followed by "rosrun" on container startup.

This is actually, in part, what roslaunch is for. It makes it easier to launch multiple nodes and nicer parameter input, but it will also start a roscore is one is not already running. In your example it would look something like this:

<launch>
  <node pkg="ROS_PackageName" type="PythonScript.py" name="my_node_name" output="screen" >
  </node>
</launch>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM