Ask Your Question

Revision history [back]

Create your docker file, here an example:

FROM ros:melodic-ros-base
# set enviroment    
ENV ROS_MASTER_URI=http://<your master IP address>:11311
ENV ROS_IP=<your node "static" IP addresse>
ENV ROS_WS=/home/catkin_ws

RUN mkdir -p $ROS_WS/src

COPY <your directory to copy on container> $ROS_WS/src

# install ros dependencies packages
RUN apt update && apt-get install -y \
    ros-melodic-desktop-full \
    ros-melodic-navigation \
    ros-melodic-moveit \
    ros-melodic-gazebo-ros-control \
    && apt-get clean 

RUN . "/opt/ros/$ROS_DISTRO/" && cd $ROS_WS && catkin_make \
    && sed --in-place --expression \ 
     '$isource "$ROS_WS/devel/setup.bash"' \

# run ros package launch file
CMD [ "roslaunch", "<your package>", "<your launch file>" ]

build your image with --network=host:

sudo docker build --network=host -t <your docker hub>/<your image name>:<your tag> .

run your container with the parameter:

sudo docker run --rm --network=host <your docker hub>/<your image name>:<your tag>

Warning This is only a workaround. In this way you are opening all ports of your host to the docker container (see docker build doc mapping the container network to the device network layer.