|
| 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) |
0 commit comments