Skip to content

Commit

Permalink
Merge pull request #70 from hollydinkel/master
Browse files Browse the repository at this point in the history
Add docker files
  • Loading branch information
hollydinkel authored Jun 15, 2023
2 parents ce58f13 + a41d861 commit 974a6ed
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
59 changes: 59 additions & 0 deletions docker/Dockerfile.noetic
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM ros:noetic-robot

# Copyright (c) 2023, UNIVERSITY OF ILLINOIS URBANA-CHAMPAIGN. All rights reserved.

# To build:
# docker build -t rmdlo-trackdlo:noetic -f Dockerfile.noetic ..

ENV HOME /root
ENV DEBIAN_FRONTEND=noninteractive

# Install system and development components
RUN apt-get update && apt-get -y --no-install-recommends install \
apt-utils \
software-properties-common \
build-essential \
cmake \
git \
python3-pip \
python3-catkin-tools \
libeigen3-dev \
libpcl-dev \
libopencv-dev \
python3-opencv \
&& apt-get -y autoremove \
&& apt-get clean

# Install required ROS components
RUN apt-get update && apt-get -y --no-install-recommends install \
ros-noetic-catkin \
ros-noetic-cv-bridge \
ros-noetic-pcl-conversions \
ros-noetic-pcl-ros \
ros-noetic-geometry-msgs \
ros-noetic-message-filters \
ros-noetic-rospy \
ros-noetic-sensor-msgs \
ros-noetic-std-msgs \
ros-noetic-tf \
ros-noetic-vision-msgs \
ros-noetic-visualization-msgs \
ros-noetic-rviz \
&& apt-get -y autoremove \
&& apt-get clean

# Install required Python components
COPY docker/requirements.txt ${HOME}
RUN python3 -m pip install -r ${HOME}/requirements.txt

# Set up a catkin workspace
ENV CATKIN_WS ${HOME}/tracking_ws
COPY . ${CATKIN_WS}/src/trackdlo
COPY docker/init_workspace.sh ${HOME}
RUN ${CATKIN_WS}/src/trackdlo/docker/init_workspace.sh
RUN echo "source ${CATKIN_WS}/devel/setup.bash" >> ${HOME}/.bashrc

ENV DISPLAY :0
ENV TERM=xterm
# Some QT-Apps do not show controls without this
ENV QT_X11_NO_MITSHM 1
15 changes: 15 additions & 0 deletions docker/init_workspace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Copyright (c) 2023, UNIVERSITY OF ILLINOIS URBANA-CHAMPAIGN. All rights reserved.

# Stop in case of any error.
set -e

source /opt/ros/noetic/setup.bash

# Create catkin workspace.
mkdir -p ${CATKIN_WS}/src
cd ${CATKIN_WS}/src
catkin init
cd ..
catkin build
6 changes: 6 additions & 0 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
numpy==1.17.4
scipy==1.5.2
opencv_python==4.4.0.44
Pillow==8.1.1
rosnumpy==0.0.5.2
scikit-image==0.21.0
42 changes: 42 additions & 0 deletions docker/run_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Copyright (c) 2023, UNIVERSITY OF ILLINOIS URBANA-CHAMPAIGN. All rights reserved.

CONTAINER_NAME=$1
if [[ -z "${CONTAINER_NAME}" ]]; then
CONTAINER_NAME=trackdlo
fi

# Specify a mapping between a host directory and a directory in the
# docker container. Change this to access a different directory.
HOST_DIR=$2
if [[ -z "${HOST_DIR}" ]]; then
HOST_DIR=`realpath ${PWD}/..`
fi

CONTAINER_DIR=$3
if [[ -z "${CONTAINER_DIR}" ]]; then
CONTAINER_DIR=/root/tracking_ws/src/trackdlo
fi

echo "Container name : ${CONTAINER_NAME}"
echo "Host directory : ${HOST_DIR}"
echo "Container directory: ${CONTAINER_DIR}"
TRACK_ID=`docker ps -aqf "name=^/${CONTAINER_NAME}$"`
if [ -z "${TRACK_ID}" ]; then
echo "Creating new trackdlo docker container."
xhost +local:root
docker run -it --privileged --network=host -v ${HOST_DIR}:${CONTAINER_DIR}:rw -v /tmp/.X11-unix:/tmp/.X11-unix:rw --env="DISPLAY" --name=${CONTAINER_NAME} rmdlo-trackdlo:noetic bash
else
echo "Found trackdlo docker container: ${TRACK_ID}."
# Check if the container is already running and start if necessary.
if [ -z `docker ps -qf "name=^/${CONTAINER_NAME}$"` ]; then
xhost +local:${TRACK_ID}
echo "Starting and attaching to ${CONTAINER_NAME} container..."
docker start ${TRACK_ID}
docker attach ${TRACK_ID}
else
echo "Found running ${CONTAINER_NAME} container, attaching bash..."
docker exec -it ${TRACK_ID} bash
fi
fi
37 changes: 37 additions & 0 deletions docs/DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## TrackDLO with Docker

TrackDLO can be tested inside of a [Docker](https://www.docker.com/) container to isolate all software and dependency changes from the host system. This document describes how to create and run a Docker image that contains a complete ROS and system environment for TrackDLO.

The current configuration was tested on an x86 host computer running Ubuntu 20.04 with Docker 24.0.1.

### Steps

1. **Download TrackDLO**
```bash
$ git clone https://github.com/RMDLO/trackdlo.git trackdlo
```

2. **Build the Docker Image**
```bash
$ cd trackdlo/docker
$ docker build -t nvidia-dope:noetic-v1 -f Dockerfile.noetic ..
```
This will take several minutes and requires an internet connection.

3. **Plug in your camera**
Docker will not recognize a USB device that is plugged in after the container is started.

4. **Run the container**
```
$ ./run_dope_docker.sh [name] [host dir] [container dir]
```
Parameters:
- `name` is an optional field that specifies the name of this image. By default, it is `nvidia-dope-v2`. By using different names, you can create multiple containers from the same image.
- `host dir` and `container dir` are a pair of optional fields that allow you to specify a mapping between a directory on your host machine and a location inside the container. This is useful for sharing code and data between the two systems. By default, it maps the directory containing dope to `/root/catkin_ws/src/dope` in the container.

Only the first invocation of this script with a given name will create a container. Subsequent executions will attach to the running container allowing you -- in effect -- to have multiple terminal sessions into a single container.

5. **Build DOPE**
Return to step 7 of the [installation instructions](../readme.md) (downloading the weights).

*Note:* Since the Docker container binds directly to the host's network, it will see `roscore` even if running outside the docker container.
1 change: 1 addition & 0 deletions docs/RUN.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Installation and execution of TrackDLO was verified with the below dependencies.
* [SciPy](https://scipy.org/install/) (Our version: 1.23.3)
* [scikit-image](https://scikit-image.org/) (Our version: 0.18.0)
* [Pillow](https://pillow.readthedocs.io/en/stable/installation.html) (Our version: 9.2.0)
* [ROS Numpy](https://pypi.org/project/rosnumpy/) (Our version: 0.0.5)

## Other Requirements

Expand Down

0 comments on commit 974a6ed

Please sign in to comment.