Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Docker support #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,75 @@ roslaunch me5413_world navigation.launch

![rviz_navigation_image](src/me5413_world/media/rviz_navigation.png)

## Docker Support
This repository provides Docker support for setting up and managing a ROS Noetic environment with GPU acceleration.
The docker folder includes the following Dockerfiles to build container images:

#### 1. `nvidia-ros-noetic.Dockerfile`
This file creates a ROS Noetic image using an NVIDIA CUDA-based Ubuntu base image, providing GPU support for ROS applications.

To build the image,

```bash
# From the root of the repository build the GPU accelerated ROS Noetic image
docker build -f docker/nvidia-ros-noetic.Dockerfile -t nvidia-ros-noetic .
```

#### 2. `dev-overlay.Dockerfile`

This file extends the ROS Noetic base image, setting up a development container with the volume-mounted `src` folder
containing all the packages. Any new packages created in the `src` folder will automatically appear inside the running container.

To build the development image,

```bash
# From the root of the repository build the development image
docker build -f docker/dev-overlay.Dockerfile -t dev-overlay .
```
### Launching the development environment
The repository includes a `docker-compose.yaml` file in the root directory to simplify launching the development environment. Use the following steps:

1. Allow X11 access for Gazebo

```bash
xhost +
```

2. Start the development environment

```bash
docker compose up
```

### Accessing the development environment

Once the container is running, you can access it using the following commands:

- With `appuser` privilages

```bash
docker exec -it dev-overlay bash
```
- With `root` privilages

```bash
docker exec -it -u 0 dev-overlay bash
```

### Customizing the development environment

The development environment can be extended by adding custom commands to `docker/dev-overlay.Dockerfile` in the designated section:

```
# Put your code here to run additional commands
#######################################################################




#######################################################################
```

## Student Tasks

### 1. Map the environment
Expand Down Expand Up @@ -188,4 +257,4 @@ We are following:

## License

The [ME5413_Final_Project](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project) is released under the [MIT License](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project/blob/main/LICENSE)
The [ME5413_Final_Project](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project) is released under the [MIT License](https://github.com/NUS-Advanced-Robotics-Centre/ME5413_Final_Project/blob/main/LICENSE)
30 changes: 30 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.9"

services:
# ROS Noetic image
nvidia-ros-noetic:
image: nvidia-ros-noetic
container_name: nvidia-ros-noetic
build:
context: .
dockerfile: docker/nvidia-ros-noetic.Dockerfile
network_mode: host
environment:
- DISPLAY=${DISPLAY}
- QT_X11_NO_MITSHM=1
- NVIDIA_DRIVER_CAPABILITIES=all
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix:rw
- ${XAUTHORITY:-$HOME/.Xauthority}:/root/.Xauthority

dev-overlay:
extends: nvidia-ros-noetic
image: dev-overlay
container_name: dev-overlay
build:
context: .
dockerfile: docker/dev-overlay.Dockerfile
network_mode: host
volumes:
- ./src:/appuser/catkin_ws/src:rw
command: sleep infinity
61 changes: 61 additions & 0 deletions docker/dev-overlay.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM nvidia-ros-noetic:latest
SHELL [ "/bin/bash", "-c" ]

# Set env variables for rosdep
ENV ROS_PYTHON_VERSION=3
ENV ROS_DISTRO=noetic

# Create new user with full permission to the volume mount
RUN useradd --create-home appuser

# Copy the src folder for volume mount
USER appuser

WORKDIR /appuser

RUN mkdir -p catkin_ws/src

COPY ./src catkin_ws/src

# Run rosdep to install dependencies
USER root

WORKDIR /appuser/catkin_ws

RUN apt-get update --fix-missing \
&& rosdep update

RUN rosdep install --from-paths src --ignore-src -r -y

# Download Gazebo models
USER appuser

WORKDIR /home/appuser

RUN git clone https://github.com/osrf/gazebo_models.git

RUN mkdir -p .gazebo/models \
&& cp -r gazebo_models/* .gazebo/models \
&& cp -r /appuser/catkin_ws/src/me5413_world/models/* .gazebo/models


# Put your code here to run additional commands
#######################################################################




#######################################################################


# Build the entire package
USER appuser

WORKDIR /appuser/catkin_ws

RUN source /opt/ros/noetic/setup.bash \
&& catkin config --install \
&& catkin build

RUN echo "source /appuser/catkin_ws/devel/setup.bash" >> ~/.bashrc

47 changes: 47 additions & 0 deletions docker/nvidia-ros-noetic.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Ubuntu 20.04 base image with NVIDIA CUDA and ROS Noetic
FROM nvidia/cudagl:11.2.1-base-ubuntu20.04
SHELL ["/bin/bash", "-c"]

# Install apt packages
ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
locales \
lsb-release

RUN dpkg-reconfigure locales

RUN apt-get update && apt-get install -y \
git \
g++ \
cmake \
gnupg \
gnupg1 \
gnupg2 \
wget

# Install ROS Noetic
RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

RUN apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

RUN apt-get update \
&& apt-get install -y --no-install-recommends ros-noetic-desktop-full

RUN apt-get install -y --no-install-recommends python3-rosdep

RUN rosdep init \
&& rosdep fix-permissions \
&& rosdep update

RUN echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc

# Install python3 dependencies
RUN apt-get install -y \
python3-pip \
python3-catkin-tools \
python3-opencv

COPY ./docker/ros_entrypoint.sh /
ENTRYPOINT [ "/ros_entrypoint.sh" ]

5 changes: 5 additions & 0 deletions docker/ros_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

source /opt/ros/noetic/setup.bash

exec "$@"