From 52c8ee2c7da8e80626a3e181c3aa30f180cc28df Mon Sep 17 00:00:00 2001 From: Nicolai Mark Sandmann Date: Fri, 19 Jan 2024 15:12:42 +0100 Subject: [PATCH] #149 Added Dockerfile and scripts for building and running the container. Updated README. --- README.md | 6 +++++ lbr_humble_docker/Dockerfile | 26 ++++++++++++++++++++++ lbr_humble_docker/container_build.sh | 19 ++++++++++++++++ lbr_humble_docker/container_new_console.sh | 2 ++ lbr_humble_docker/container_start.sh | 5 +++++ 5 files changed, 58 insertions(+) create mode 100644 lbr_humble_docker/Dockerfile create mode 100755 lbr_humble_docker/container_build.sh create mode 100755 lbr_humble_docker/container_new_console.sh create mode 100755 lbr_humble_docker/container_start.sh diff --git a/README.md b/README.md index 1ffa6d30..f90a5320 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,12 @@ vcs import src < src/repos.yaml rosdep install --from-paths src --ignore-src -r -y colcon build --symlink-install ``` +Copy the Dockerfile and the container scripts to the lbr-stack directory. Build and start the container. +```shell +cp -r src/lbr_fri_ros2_stack/lbr_humble_docker/* . +chmod +x container_build.sh +sudo ./container_build.sh +``` Next, launch the simulation via ```shell source install/setup.bash diff --git a/lbr_humble_docker/Dockerfile b/lbr_humble_docker/Dockerfile new file mode 100644 index 00000000..09af65ab --- /dev/null +++ b/lbr_humble_docker/Dockerfile @@ -0,0 +1,26 @@ +FROM ros:humble-ros-base-jammy + +SHELL ["/bin/bash", "-c"] + +RUN apt update -y +RUN apt install vim python-is-python3 python3-pip python3-colcon-common-extensions -y +RUN pip3 install scipy numpy +# create workspace and build package +# source workspace +RUN source /opt/ros/humble/setup.bash && echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc + +# create workspace +RUN mkdir -p home/ros2_ws/src +WORKDIR /home/ros2_ws/ + +COPY ./src /home/ros2_ws/src +RUN rosdep install -i --from-path src --rosdistro humble -y + +# "--symlink-install" allows the code in the locally mounted volume ./src to be adjusted without rebuilding +RUN source /opt/ros/humble/setup.bash && colcon build --symlink-install + +# source overlay workspace +RUN source /home/ros2_ws/install/setup.bash && echo "source /home/ros2_ws/install/setup.bash" >> ~/.bashrc +CMD ["/bin/bash"] + + diff --git a/lbr_humble_docker/container_build.sh b/lbr_humble_docker/container_build.sh new file mode 100755 index 00000000..ddaed354 --- /dev/null +++ b/lbr_humble_docker/container_build.sh @@ -0,0 +1,19 @@ +# dont forget to chmod +x container_build.sh +xhost + + +docker rm lbr_stack_container + +docker build -t lbr_stack_container . + +docker run -it \ + --network host \ + --ipc host \ + --volume ./src:/home/ros2_ws/src \ + --volume /tmp/.X11-unix:/tmp/.X11-unix \ + --volume /dev/shm:/dev/shm \ + --volume /dev:/dev --privileged \ + --env DISPLAY \ + --env QT_X11_NO_MITSHM=1 \ + --name lbr_stack_container \ + lbr_stack_container + diff --git a/lbr_humble_docker/container_new_console.sh b/lbr_humble_docker/container_new_console.sh new file mode 100755 index 00000000..f3e79746 --- /dev/null +++ b/lbr_humble_docker/container_new_console.sh @@ -0,0 +1,2 @@ +# dont forget to chmod +x container_new_console.sh +docker exec -it lbr_stack_container bash diff --git a/lbr_humble_docker/container_start.sh b/lbr_humble_docker/container_start.sh new file mode 100755 index 00000000..37700410 --- /dev/null +++ b/lbr_humble_docker/container_start.sh @@ -0,0 +1,5 @@ +# dont forget to chmod +x container_new_console.sh +xhost + + +docker start lbr_stack_container -i +