Skip to content

Commit c549d3c

Browse files
Merge pull request #203 from utn-mi/gamal/rcs-docker
Add Development Dockerfile for RCS
2 parents b323bd6 + 6769bb0 commit c549d3c

File tree

7 files changed

+255
-0
lines changed

7 files changed

+255
-0
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/build/

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@ pip config --site set global.no-build-isolation false
2828
pip install -ve .
2929
```
3030

31+
## Docker (GUI + GPU + HW add-ons)
32+
33+
**Prereqs:** Docker + docker-compose, X11 on host, NVIDIA driver + NVIDIA Container Toolkit (legacy `runtime: nvidia`).
34+
**Layout:** `docker/Dockerfile`, overrides in `docker/compose/` (`base.yml`, `gui.yml`, `gpu.yml`, `hw.yml`).
35+
36+
### Build the image
37+
`docker-compose -f docker/compose/base.yml build dev`
38+
39+
### (GUI) allow X access (host)
40+
`export XAUTHORITY=${XAUTHORITY:-$HOME/.Xauthority}`
41+
`xhost +si:localuser:root`
42+
43+
### Run container with GUI + GPU + HW and open a shell
44+
`docker-compose -f docker/compose/base.yml -f docker/compose/gui.yml -f docker/compose/gpu.yml -f docker/compose/hw.yml run --rm run bash`
45+
*(Use fewer `-f` files for lighter setups, e.g., GUI+GPU without HW.)*
46+
47+
### Inside the container
48+
`pip install -ve extensions/rcs_fr3`
49+
`cd examples`
50+
`python fr3_env_cartesian_control.py`
51+
52+
### Troubleshooting
53+
- **`nvidia-smi` missing in container:** ensure it exists on host at `/usr/bin/nvidia-smi` (GPU override bind-mounts it).
54+
- **GUI can’t open:** re-run the `xhost` command and confirm `$DISPLAY` is set on the host.
55+
56+
3157
## Usage
3258
The python package is called `rcs`.
3359

docker/Dockerfile

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Base image with Python 3.10 and slim Debian system
2+
FROM python:3.10-slim
3+
4+
# System configuration
5+
ENV DEBIAN_FRONTEND=noninteractive \
6+
PYTHONDONTWRITEBYTECODE=1 \
7+
PYTHONUNBUFFERED=1 \
8+
CMAKE_BUILD_PARALLEL_LEVEL=2 \
9+
SKBUILD_BUILD_OPTIONS="-j2" \
10+
MAKEFLAGS="-j2"
11+
#############################################################################
12+
# Explanation of environment variables:
13+
# DEBIAN_FRONTEND=noninteractive: Disables interactive prompts during apt-get install.
14+
# PYTHONDONTWRITEBYTECODE=1: Prevents .pyc files, keeping the image clean.
15+
# PYTHONUNBUFFERED=1: Ensures logs are written directly (no buffering).
16+
# Parallel build settings for CMake, scikit-build, and make to improve build speed.
17+
#############################################################################
18+
19+
# create a user to avoid running as root
20+
RUN useradd -ms /bin/bash devuser
21+
WORKDIR /home/devuser
22+
USER root
23+
24+
# Install system dependencies (from debian_deps.txt manually inlined here)
25+
RUN apt-get update && apt-get install -y --no-install-recommends \
26+
build-essential \
27+
cmake \
28+
git \
29+
libpoco-dev \
30+
libeigen3-dev \
31+
libxslt-dev \
32+
libcoin-dev \
33+
libccd-dev \
34+
libglfw3-dev \
35+
libboost-all-dev \
36+
liblzma-dev \
37+
libxml2-dev \
38+
libxslt1-dev \
39+
ninja-build \
40+
clang \
41+
clang-format \
42+
clang-tidy \
43+
pkg-config \
44+
curl \
45+
unzip \
46+
wget \
47+
libgl1 \
48+
patchelf \
49+
python3-venv \
50+
libegl-dev \
51+
libegl1-mesa-dev \
52+
libglib2.0-dev \
53+
mesa-utils \
54+
&& rm -rf /var/lib/apt/lists/*
55+
56+
# Remove root password so `su -` works from devuser
57+
RUN passwd -d root
58+
59+
60+
# Switch to non-root user
61+
USER devuser
62+
63+
# Set up virtual environment (Python)
64+
RUN python3 -m venv /home/devuser/.venv
65+
# prepend /home/devuser/.venv/bin to the existing PATH
66+
# This ensures that the virtual environment's Python and pip are used by default.
67+
ENV PATH="/home/devuser/.venv/bin:$PATH"
68+
69+
# Copy project files into container
70+
COPY --chown=devuser . /home/devuser/project
71+
WORKDIR /home/devuser/project
72+
73+
# Upgrade pip and install project build tools
74+
RUN pip install --upgrade pip setuptools
75+
RUN pip config --site set global.no-build-isolation false
76+
77+
# Install development dependencies
78+
RUN pip install -r requirements_dev.txt
79+
80+
# Install the package in editable mode (CMake + pybind11 + scikit-build-core triggered)
81+
RUN pip install -e . --no-cache-dir --verbose --no-build-isolation
82+
83+
# Default command that runs when you start a container without specifying a command explicitly.
84+
CMD ["python3"]
85+
86+
######################################################################
87+
# Build the Docker image with specified memory limits
88+
# To build the Docker image, run the following command in the terminal:
89+
# docker build --memory=4g --memory-swap=6g . -t rcs-dev
90+
######################################################################
91+
# --memory=4g Limit the build process to 4 GB of RAM
92+
# --memory-swap=6g Limit total memory (RAM + swap) to 6 GB
93+
# . Use current directory as the Docker context
94+
# -t rcs-dev Tag the built image as "rcs-dev"
95+
######################################################################
96+
97+
######################################################################
98+
# Run the Docker container interactively (without GUI)
99+
# docker run -it --rm rcs-dev bash
100+
######################################################################
101+
# -it Interactive mode with TTY
102+
# --rm Automatically remove container after exit
103+
# rcs-dev Name of the Docker image to run
104+
# bash Start an interactive bash shell inside the container
105+
######################################################################
106+
107+
######################################################################
108+
# Optional: Run GUI applications from inside the container
109+
# First, allow X11 connections from Docker containers:
110+
# Run this command on the host machine:
111+
# xhost +local:docker
112+
######################################################################
113+
# xhost A utility to manage X11 display access control
114+
# +local:docker Grant X11 access to Docker containers running locally
115+
######################################################################
116+
117+
######################################################################
118+
# Run container with GUI support (no GPU)
119+
# docker run -it --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --shm-size=1g rcs-dev bash
120+
######################################################################
121+
# -e DISPLAY=$DISPLAY Pass display info to container
122+
# -v /tmp/.X11-unix:/tmp/.X11-unix Mount X11 socket for GUI apps
123+
# --shm-size=1g Increase shared memory for rendering (useful for tools like MuJoCo)
124+
######################################################################
125+
126+
######################################################################
127+
# Run container with NVIDIA GPU support
128+
# Make sure NVIDIA Container Toolkit is installed and configured
129+
# For more info: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html
130+
# docker run -it --rm --gpus all --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --shm-size=1g rcs-dev bash
131+
######################################################################
132+
# --gpus all Enable all available GPUs
133+
# --runtime=nvidia Use NVIDIA runtime for GPU access
134+
# -e NVIDIA_VISIBLE_DEVICES=all Expose all GPUs inside container
135+
# -e NVIDIA_DRIVER_CAPABILITIES=all Enable all GPU features (e.g., graphics, compute)
136+
# Other flags same as GUI setup above
137+
######################################################################
138+
# Run the container with NVIDIA GPU support and hardware access:
139+
# docker run -it --rm --gpus all --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --shm-size=2g --network host --privileged --cap-add=SYS_NICE --ulimit rtprio=99 --ulimit rttime=-1 --ulimit memlock=8428281856 -v /dev:/dev rcs-dev bash
140+
# Optional flags for running the container with hardware access:
141+
# --network host \ # Use the host's network stack (needed for low-latency ROS comms)
142+
# --privileged \ # Grant full device and kernel access (required for hardware control)
143+
# --cap-add=SYS_NICE \ # Allow processes to raise their scheduling priority
144+
# --ulimit rtprio=99 \ # Enable real-time priority up to 99
145+
# --ulimit rttime=-1 \ # Disable CPU time limit for real-time threads
146+
# --ulimit memlock=8428281856 \ # Lock ~8GB of RAM to prevent memory swapping
147+
# -v /dev:/dev \ # Mount all host devices for hardware access (e.g., Franka arm)

docker/compose/base.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
services:
2+
# Build / dev: the ONLY service that mounts your source
3+
dev:
4+
build:
5+
context: ${PWD} # run commands from the repo root
6+
dockerfile: docker/Dockerfile
7+
image: rcs-dev
8+
user: root
9+
tty: true
10+
stdin_open: true
11+
working_dir: /home/devuser/project
12+
volumes:
13+
- ${PWD}:/home/devuser/project
14+
environment:
15+
PYTHONUNBUFFERED: "1"
16+
shm_size: "2g"
17+
18+
# Runtime base: NO source mount here
19+
run:
20+
image: rcs-dev
21+
user: root
22+
tty: true
23+
stdin_open: true
24+
working_dir: /home/devuser/project
25+
environment:
26+
PYTHONUNBUFFERED: "1"
27+
shm_size: "2g"
28+
29+
30+
# Build the dev image
31+
# docker-compose -f compose/base.yml build dev
32+
# Run the dev container
33+
# docker-compose \
34+
# -f compose/base.yml \
35+
# -f compose/gui.yml \
36+
# -f compose/gpu.yml \
37+
# -f compose/hw.yml \
38+
# run --rm run bash

docker/compose/gpu.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: "3.8"
2+
3+
services:
4+
run:
5+
# Old-compose compatible GPU enablement
6+
runtime: nvidia
7+
privileged: true
8+
network_mode: host
9+
environment:
10+
NVIDIA_VISIBLE_DEVICES: "all"
11+
NVIDIA_DRIVER_CAPABILITIES: "all"
12+

docker/compose/gui.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3.8"
2+
3+
services:
4+
run:
5+
environment:
6+
DISPLAY: ${DISPLAY}
7+
XAUTHORITY: /tmp/.docker.xauth
8+
QT_X11_NO_MITSHM: "1"
9+
volumes:
10+
- /tmp/.X11-unix:/tmp/.X11-unix:rw
11+
- ${XAUTHORITY:-$HOME/.Xauthority}:/tmp/.docker.xauth:ro

docker/compose/hw.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: "3.8"
2+
3+
services:
4+
run:
5+
privileged: true
6+
volumes:
7+
- /dev:/dev
8+
cap_add:
9+
- SYS_NICE
10+
ulimits:
11+
rtprio: 99
12+
rttime: -1
13+
memlock:
14+
soft: 8428281856
15+
hard: 8428281856
16+
# If you prefer least-privilege instead of /dev:/dev, swap in specific devices:
17+
# devices:
18+
# - /dev/video0:/dev/video0
19+
# - /dev/ttyUSB0:/dev/ttyUSB0
20+
# - /dev/dri:/dev/dri

0 commit comments

Comments
 (0)