g1_mujoco / Dockerfile
nepyope's picture
Upload folder using huggingface_hub
1551216 verified
Raw
History Blame Contribute Delete
4.32 kB
# Self-contained HF Docker Space for the headless Unitree G1 MuJoCo sim.
#
# Mirrors lerobot/visualize_dataset: the Space repo holds this Dockerfile + the
# sim scripts, and HF builds it server-side (no image pushed to a registry).
#
# Access model:
# * app_port 7860 serves the meshcat viewer (public Space URL shows the live sim)
# * control is over SSH (Dev Mode, free on Team/Enterprise orgs): ssh -L forwards
# the robot's ZMQ ports (6000/6001/6002/6003)
# The sim behaves exactly like a physical G1, so the lerobot client command is
# identical -- only robot_ip changes (127.0.0.1 through the tunnel).
FROM python:3.12-slim
ENV DEBIAN_FRONTEND=noninteractive \
CYCLONEDDS_HOME=/opt/cyclonedds \
LD_LIBRARY_PATH=/opt/cyclonedds/lib \
MUJOCO_GL=osmesa \
SDL_VIDEODRIVER=dummy \
SDL_AUDIODRIVER=dummy \
G1_SIM_DIR=/opt/g1-sim \
G1_PUBLISH_IMAGES=0 \
G1_CAMERA_PORT=5555 \
G1_ENABLE_MESHCAT=1 \
G1_MESHCAT_DEBUG=0 \
G1_ENABLE_VIEW=1 \
G1_MESHCAT_WEB_PORT=7000 \
G1_HEALTH_PORT=7860
# System deps: build tools + cmake (CycloneDDS), OSMesa (headless MuJoCo rendering)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential git curl cmake pkg-config ca-certificates \
libgl1 libglx-mesa0 libosmesa6 libosmesa6-dev \
libx11-6 libxrandr2 libxinerama1 libxcursor1 libxi6 libxext6 libxfixes3 \
&& rm -rf /var/lib/apt/lists/*
# --- CycloneDDS C library (required by unitree_sdk2py and the cyclonedds wheel) ---
RUN git clone --depth 1 -b releases/0.10.x \
https://github.com/eclipse-cyclonedds/cyclonedds /tmp/cdds \
&& cmake -S /tmp/cdds -B /tmp/cdds/build \
-DCMAKE_INSTALL_PREFIX=${CYCLONEDDS_HOME} -DBUILD_IDLC=ON -DBUILD_DDSPERF=OFF \
&& cmake --build /tmp/cdds/build --target install -j"$(nproc)" \
&& rm -rf /tmp/cdds
# --- Python deps: hub sim requirements + DDS + Unitree SDK (no lerobot / torch) ---
RUN pip install --no-cache-dir \
"mujoco>=3.0.0" "numpy>=1.24.0" scipy pyyaml loguru pygame termcolor glfw gymnasium \
opencv-python-headless pyzmq "msgpack>=1.0.0" "msgpack-numpy>=0.4.8" matplotlib meshcat \
huggingface_hub aiohttp \
"cyclonedds==0.10.2"
# --- Unitree SDK (from git). pip drops the prebuilt native .so files (crc_*.so),
# so install then copy them into the installed package by hand. ---
RUN git clone --depth 1 https://github.com/unitreerobotics/unitree_sdk2_python.git /tmp/usdk \
&& pip install --no-cache-dir /tmp/usdk \
&& LIBDIR="$(python -c 'import os, unitree_sdk2py; print(os.path.join(os.path.dirname(unitree_sdk2py.__file__), "utils", "lib"))')" \
&& mkdir -p "${LIBDIR}" \
&& cp -v /tmp/usdk/unitree_sdk2py/utils/lib/* "${LIBDIR}/" \
&& rm -rf /tmp/usdk
# --- Bake the hub sim (env.py, run_sim.py, sim/, assets) at a pinned revision ---
ARG G1_ENV_REV=a38dc8617f0fca51b38e9354dc58ee35ad850fb5
RUN python -c "import os, shutil; from huggingface_hub import snapshot_download; \
d = snapshot_download('lerobot/unitree-g1-mujoco', revision='${G1_ENV_REV}'); \
shutil.copytree(d, os.environ['G1_SIM_DIR'], symlinks=False, dirs_exist_ok=True)" \
&& python -c "import os, yaml; p = os.path.join(os.environ['G1_SIM_DIR'], 'config.yaml'); \
c = yaml.safe_load(open(p)); c['ENABLE_ONSCREEN'] = False; yaml.safe_dump(c, open(p, 'w'))"
# Extra packages required by HF Spaces Dev Mode (SSH + VS Code server + git push).
# Kept as a late layer so it doesn't invalidate the CycloneDDS/pip build cache.
RUN apt-get update && apt-get install -y --no-install-recommends \
wget procps git-lfs \
&& rm -rf /var/lib/apt/lists/*
COPY g1_sim_entry.py ${G1_SIM_DIR}/g1_sim_entry.py
COPY g1_sim_bridge.py ${G1_SIM_DIR}/g1_sim_bridge.py
COPY g1_sim_meshcat.py ${G1_SIM_DIR}/g1_sim_meshcat.py
COPY g1_sim_ctl.py ${G1_SIM_DIR}/g1_sim_ctl.py
COPY g1_health.py ${G1_SIM_DIR}/g1_health.py
COPY g1_view_server.py ${G1_SIM_DIR}/g1_view_server.py
COPY g1_sim_start.sh ${G1_SIM_DIR}/g1_sim_start.sh
RUN chmod +x ${G1_SIM_DIR}/g1_sim_start.sh
EXPOSE 7860 7000 6000 6001 6002 6003
WORKDIR ${G1_SIM_DIR}
# CMD (not ENTRYPOINT): HF Spaces Dev Mode overrides the entrypoint with its own
# daemon and runs the app as a subprocess via CMD. Works in normal mode too.
CMD ["bash", "g1_sim_start.sh"]