├── docker ├── bash_profile ├── rosbox_entrypoint.sh ├── bashrc └── Dockerfile ├── .gitignore ├── target └── go.sh ├── LICENSE ├── README.md └── init-ros-box.sh /docker/bash_profile: -------------------------------------------------------------------------------- 1 | # 2 | # ~/.bash_profile 3 | # 4 | 5 | [[ -f ~/.bashrc ]] && . ~/.bashrc 6 | -------------------------------------------------------------------------------- /docker/rosbox_entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # setup ros environment 4 | source /opt/ros/${ROS_DISTRO}/setup.bash 5 | 6 | bash 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | bin/ 3 | lib/ 4 | msg_gen/ 5 | srv_gen/ 6 | msg/*Action.msg 7 | msg/*ActionFeedback.msg 8 | msg/*ActionGoal.msg 9 | msg/*ActionResult.msg 10 | msg/*Feedback.msg 11 | msg/*Goal.msg 12 | msg/*Result.msg 13 | msg/_*.py 14 | 15 | # Generated by dynamic reconfigure 16 | *.cfgc 17 | /cfg/cpp/ 18 | /cfg/*.py 19 | 20 | # Ignore generated docs 21 | *.dox 22 | *.wikidoc 23 | 24 | # eclipse stuff 25 | .project 26 | .cproject 27 | 28 | # qcreator stuff 29 | CMakeLists.txt.user 30 | 31 | srv/_*.py 32 | *.pcd 33 | *.pyc 34 | qtcreator-* 35 | *.user 36 | 37 | /planning/cfg 38 | /planning/docs 39 | /planning/src 40 | 41 | *~ 42 | 43 | # Emacs 44 | .#* 45 | 46 | # Catkin custom files 47 | CATKIN_IGNORE 48 | -------------------------------------------------------------------------------- /docker/bashrc: -------------------------------------------------------------------------------- 1 | # 2 | # ~/.bashrc 3 | # 4 | 5 | # If not running interactively, don't do anything 6 | [[ $- != *i* ]] && return 7 | 8 | alias ls='ls --color=auto' 9 | alias ll='ls -l' 10 | alias rm='rm -i' 11 | alias mv='mv -i' 12 | alias cp='cp -i' 13 | alias grep='grep --color=auto' 14 | export EDITOR='vim' 15 | export LESS="-iMSx4 -FX -SR" 16 | alias less="less ${LESS}" 17 | export PAGER="less ${LESS}" 18 | export QT_X11_NO_MITSHM=1 19 | 20 | function returncode 21 | { 22 | returncode=$? 23 | if [ $returncode != 0 ]; then 24 | echo "[$returncode]" 25 | else 26 | echo "" 27 | fi 28 | } 29 | 30 | if [[ ${EUID} == 0 ]] 31 | then 32 | PS1='\[\033[0;31m\]$(returncode)\[\033[01;31m\]\u\[\033[00m\]@\[\033[01;33m\]\h\[\033[01;34m\] ${PWD} \$\[\033[00m\] ' 33 | else 34 | PS1='\[\033[0;31m\]$(returncode)\[\033[01;32m\]\u\[\033[00m\]@\[\033[01;33m\]\h\[\033[01;34m\] ${PWD} \$\[\033[00m\] ' 35 | fi 36 | 37 | export BUILDDIR=/tmp 38 | export MAKEFLAGS="-j$(nproc) $MAKEFLAGS" 39 | export LD_LIBRARY_PATH="/usr/lib:$LD_LIBRARY_PATH" 40 | -------------------------------------------------------------------------------- /target/go.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | current_dir=`pwd -P` 4 | script_dir="$( cd "$(dirname "$0")" ; pwd -P )" 5 | container_id=`cat "${script_dir}/docker_id"` 6 | 7 | sudo=y 8 | 9 | # If user is part of docker group, sudo isn't necessary 10 | if groups $USER | grep &>/dev/null '\bdocker\b'; then 11 | sudo = n 12 | fi 13 | 14 | if [ "${container_id}" == "" ] 15 | then 16 | echo "Error: No docker id found in '${script_dir}/docker_id'" 17 | exit 1 18 | fi 19 | 20 | # Check if the container is running 21 | 22 | if [ "$sudo" = "y" ]; then 23 | 24 | if [ "`sudo docker ps -qf "id=${container_id}"`" == "" ] 25 | then 26 | echo "Starting previously stopped container..." 27 | sudo docker start "${container_id}" 28 | fi 29 | 30 | # Joining the container 31 | sudo docker exec -ti ${container_id} /rosbox_entrypoint.sh 32 | else 33 | if [ "`docker ps -qf "id=${container_id}"`" == "" ] 34 | then 35 | echo "Starting previously stopped container..." 36 | docker start "${container_id}" 37 | fi 38 | 39 | docker exec -ti ${container_id} /rosbox_entrypoint.sh 40 | fi 41 | 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Pierre Killy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG ros_distro 2 | ARG uid 3 | ARG gid 4 | FROM osrf/ros:${ros_distro}-desktop-full 5 | 6 | ARG ros_distro 7 | ARG uid 8 | ARG gid 9 | 10 | RUN apt-get update && \ 11 | DEBIAN_FRONTEND=noninteractive apt-get -yq --force-yes install \ 12 | sudo \ 13 | python-catkin-tools \ 14 | dialog \ 15 | less \ 16 | x-window-system \ 17 | mesa-utils 18 | 19 | RUN mkdir -p /home/${ros_distro}-dev/catkin_ws/src && \ 20 | echo "${ros_distro}-dev:x:${uid}:${gid}:Developer,,,:/home/${ros_distro}-dev:/bin/bash" >> /etc/passwd && \ 21 | echo "${ros_distro}-dev:x:${gid}:" >> /etc/group && \ 22 | echo "${ros_distro}-dev ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/${ros_distro}-dev && \ 23 | chmod 0440 /etc/sudoers.d/${ros_distro}-dev && \ 24 | chown ${uid}:${gid} -R /home/${ros_distro}-dev 25 | 26 | USER ${ros_distro}-dev 27 | ENV HOME /home/${ros_distro}-dev 28 | COPY bashrc /home/${ros_distro}-dev/.bashrc 29 | COPY bashrc /root/.bashrc 30 | COPY bash_profile /home/${ros_distro}-dev/.bash_profile 31 | COPY bash_profile /root/.bash_profile 32 | 33 | COPY rosbox_entrypoint.sh /rosbox_entrypoint.sh 34 | ENTRYPOINT /rosbox_entrypoint.sh 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-ros-box 2 | 3 | Dockerized [ROS](http://www.ros.org/) environment with hardware accelerated X11 support based on [ros-lunar-desktop-full](https://hub.docker.com/r/osrf/ros/). 4 | 5 | Using this project you will be able to run a complete ROS environment inside a Docker container. 6 | 7 | This is very handful for example if your host operating system is *not* debian based. 8 | 9 | 10 | # Credits 11 | 12 | This project is inspired by [docker-browser-ros](https://github.com/sameersbn/docker-browser-box), [this blog post from Fabio Rehm](http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/) as well as [docker-opengl-mesa](https://github.com/thewtex/docker-opengl-mesa) for the hardware acceleration support. 13 | 14 | 15 | # Usage 16 | 17 | 1. Clone the repository: 18 | ``` 19 | git clone https://github.com/pierrekilly/docker-ros-box.git 20 | ``` 21 | 22 | 2. Initialize your ROS box: 23 | ``` 24 | ./docker-ros-box/init-ros-box.sh [ros_distro] [target] 25 | ros_distro The ROS distribution to work with (lunar, kinetic, etc.) 26 | target The target directory to deploy the basic setup 27 | ``` 28 | Building the docker container image can take some time depending on your internet connexion. Please be patient. 29 | 30 | Once the initialization is done, your dockerized ROS box is ready. 31 | 32 | In the `target` directory you will find 4 files: 33 | 34 | - `ros_distro`: This file contains the ROS distribution used in your project. Do not touch this file. 35 | - `src`: Put your ROS project sources in this directory. It is automatically mounted in ~/catkin_ws/src inside the ROS box so you can work there from your host system. 36 | - `go.sh`: Run this script to open a shell in in the container. Automatically starts the container if it's not running. 37 | 38 | 3. Connect to your ROS box 39 | ``` 40 | cd [target] 41 | ./go.sh 42 | ``` 43 | 44 | # Contribute 45 | 46 | Feel free to use this project, fork it and improve it. If you do so, please commit your modifications and open a PR. Thanks! :) 47 | 48 | 49 | # Author 50 | 51 | [Pierre Killy](https://www.linkedin.com/in/pierrekilly/) 52 | 53 | 54 | # License 55 | 56 | MIT 57 | -------------------------------------------------------------------------------- /init-ros-box.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | current_dir=`pwd -P` 6 | script_dir="$( cd "$(dirname "$0")" ; pwd -P )" 7 | 8 | sudo=y 9 | 10 | # If user is part of docker group, sudo isn't necessary 11 | if groups $USER | grep &>/dev/null '\bdocker\b'; then 12 | sudo=n 13 | fi 14 | 15 | if [ "$2" == "" ] 16 | then 17 | echo 18 | echo "Builds a docker image to run ROS and deploys a basic setup to work with it" 19 | echo 20 | echo "Usage: `basename $0` [ros_distro] [target]" 21 | echo " ros_distro The ROS distribution to work with (lunar, kinetic, etc.)" 22 | echo " target The target directory to deploy the basic setup" 23 | echo 24 | exit 1 25 | fi 26 | 27 | ros_distro="$1" 28 | target="$2" 29 | image_tag="docker-ros-box-${ros_distro}" 30 | uid=`id -u` 31 | gid=`id -g` 32 | user_name="${ros_distro}-dev" 33 | 34 | # Make sure the target exists 35 | if [ ! -d "${target}" ] 36 | then 37 | mkdir -p "${target}" 38 | fi 39 | target=$( cd "${target}" ; pwd -P ) 40 | 41 | 42 | echo "Prepare the target environment..." 43 | # Copy target files 44 | /bin/cp -Ri "${script_dir}/target/"* "${target}/" 45 | if [ ! -d "${target}/src" ] 46 | then 47 | mkdir "${target}/src" 48 | fi 49 | 50 | # Build the docker image 51 | echo "Build the docker image... (This can take some time)" 52 | cd "${script_dir}/docker" 53 | if [ "$sudo" = "n" ]; then 54 | docker build \ 55 | --quiet \ 56 | --build-arg ros_distro="${ros_distro}" \ 57 | --build-arg uid="${uid}" \ 58 | --build-arg gid="${gid}" \ 59 | -t ${image_tag} \ 60 | . 61 | else 62 | sudo docker build \ 63 | --quiet \ 64 | --build-arg ros_distro="${ros_distro}" \ 65 | --build-arg uid="${uid}" \ 66 | --build-arg gid="${gid}" \ 67 | -t ${image_tag} \ 68 | . 69 | fi 70 | 71 | echo "create a new container from this image..." 72 | container_name="`echo ${target} | sed -e 's/[^a-zA-Z0-9_.-][^a-zA-Z0-9_.-]*/-/g' | sed -e 's/^[^a-zA-Z0-9]*//g'`" 73 | cd "${target}" 74 | 75 | XSOCK=/tmp/.X11-unix 76 | XAUTH=/tmp/.docker.xauth 77 | touch $XAUTH 78 | xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - 79 | 80 | if [ "$sudo" = "n" ]; then 81 | docker create \ 82 | -e DISPLAY=$DISPLAY \ 83 | --volume=$XSOCK:$XSOCK:rw \ 84 | --volume=$XAUTH:$XAUTH:rw \ 85 | --env="XAUTHORITY=${XAUTH}" \ 86 | --device=/dev/dri/card0:/dev/dri/card0 \ 87 | -v "${target}/src:/home/${ros_distro}-dev/catkin_ws/src" \ 88 | --name "${container_name}" \ 89 | -it ${image_tag} 90 | 91 | docker ps -aqf "name=${container_name}" > "${target}/docker_id" 92 | else 93 | sudo docker create \ 94 | -e DISPLAY=$DISPLAY \ 95 | --volume=$XSOCK:$XSOCK:rw \ 96 | --volume=$XAUTH:$XAUTH:rw \ 97 | --env="XAUTHORITY=${XAUTH}" \ 98 | --device=/dev/dri/card0:/dev/dri/card0 \ 99 | -v "${target}/src:/home/${ros_distro}-dev/catkin_ws/src" \ 100 | --name "${container_name}" \ 101 | -it ${image_tag} 102 | 103 | sudo docker ps -aqf "name=${container_name}" > "${target}/docker_id" 104 | fi 105 | chmod 444 "${target}/docker_id" 106 | 107 | # That's it! 108 | cd "${current_dir}" 109 | 110 | echo 111 | echo "Your dockerized ROS box is now ready in '${target}'." 112 | echo "There you will find:" 113 | echo " docker_id This file contains the ROS distribution used in your project." 114 | echo " Do not touch this file." 115 | echo " src Put your ROS project sources in this directory." 116 | echo " It is automatically mounted in ~/catkin_ws/src inside the ROS box." 117 | echo " go.sh Run this script to start the container and/or open a shell in it." 118 | echo 119 | echo "Have fun!" 120 | echo 121 | --------------------------------------------------------------------------------