# -- stable-diffusion.cpp build for AMD ROCm 10 and gfx1201 ------------------- FROM rocm/dev-ubuntu-26.04:10.1.0-full ARG HOST_UID="1000" ARG HOST_GID="$HOST_UID" ARG SD_CPP_REPO="https://github.com/leejet/stable-diffusion.cpp" ARG SD_CPP_REF="master" ARG SD_CPP_USER="stable-diffusion-cpp" ARG ROCM_ARCH="gfx1201" ENV DEBIAN_FRONTEND="noninteractive" # Install build dependencies RUN apt-get update && \ apt-get install -y cmake curl git libcurl4-openssl-dev nano ninja-build && \ rm -rf /var/lib/apt/lists/* # Set up a user and group that match the host's UID and GID to avoid permission issues with mounted volumes RUN \ if getent group "${HOST_GID}" > /dev/null 2>&1; then \ OLD_GROUP=$(getent group "${HOST_GID}" | cut -d: -f1); \ groupmod -n "${SD_CPP_USER}" "$OLD_GROUP"; \ else \ groupadd --system --gid "${HOST_GID}" "${SD_CPP_USER}"; \ fi && \ if getent passwd "${HOST_UID}" > /dev/null 2>&1; then \ OLD_USER=$(getent passwd "${HOST_UID}" | cut -d: -f1); \ usermod -l "${SD_CPP_USER}" -d "/home/${SD_CPP_USER}" -m "$OLD_USER"; \ else \ useradd --system --uid "${HOST_UID}" --gid "${HOST_GID}" --home "/home/${SD_CPP_USER}" --create-home "${SD_CPP_USER}"; \ fi # Build stable-diffusion.cpp from source (produces the sd-server binary) WORKDIR /opt/stable-diffusion-cpp RUN git clone --recursive "${SD_CPP_REPO}" . && \ git checkout "${SD_CPP_REF}" && \ git submodule update --init --recursive RUN HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \ cmake -S . \ -B build \ -G "Ninja" \ -DAMDGPU_TARGETS="${ROCM_ARCH}" \ -DGPU_TARGETS="${ROCM_ARCH}" \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_C_COMPILER=/opt/rocm/llvm/bin/clang \ -DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++ \ -DSD_HIPBLAS=ON \ && cmake --build build --config Release -j$(nproc) # Register ROCm with the dynamic loader. The TheRock-built base image ships no # /etc/ld.so.conf.d entry for /opt/rocm/lib, unlike the deb-based # rocm/dev-ubuntu-24.04 images it replaced, and CMake deliberately emits no # RUNPATH here because /opt/rocm/lib is one of HIP's implicit link directories. # Without this, sd-server aborts at startup on a missing libamdhip64/libhipblas. # Only /opt/rocm/lib is added: ROCm's bundled sysdeps sit in # lib/rocm_sysdeps/lib and are resolved through $ORIGIN, so nothing here shadows # a system library. Kept after the build so it stays a cheap layer that does not # invalidate the compile cache. RUN echo '/opt/rocm/lib' > /etc/ld.so.conf.d/rocm.conf && \ ldconfig COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh && \ chown -R "${SD_CPP_USER}:${SD_CPP_USER}" /opt/stable-diffusion-cpp "/home/${SD_CPP_USER}" # Set environment variables for the user and application ENV USER="${SD_CPP_USER}" ENV HOME="/home/${USER}" ENV UID="${HOST_UID}" ENV GID="${HOST_GID}" ENV XDG_CACHE_HOME="${HOME}/.cache" ENV HIP_COMPILER_CACHE_DIR="${XDG_CACHE_HOME}/HIP" ENV AMD_COMGR_CACHE_DIR="${XDG_CACHE_HOME}/comgr" # Run stable-diffusion.cpp WORKDIR "${HOME}" USER "${USER}" EXPOSE 8000/tcp ENTRYPOINT ["/entrypoint.sh"]