Add Docker-based build system with GPU-enabled builder and runtime containers

This commit is contained in:
Shang Chieh Tseng
2025-11-07 12:48:05 +08:00
parent 5744fb792a
commit 94bbfbb2e7
8 changed files with 750 additions and 2 deletions

55
docker/builder/Dockerfile Normal file
View File

@@ -0,0 +1,55 @@
FROM nvidia/cuda:11.4.3-devel-rockylinux8
# Update OS and install cuda toolkit 11.4 and nvdia driver 470
#RUN dnf -y update\
# && dnf -y install epel-release\
# && dnf -y config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo\
# && dnf -y module install nvidia-driver:470-dkms\
# && dnf -y install cuda-11-4
# Post install, setup path
#COPY cuda-11.4.sh /etc/profile.d/cuda-11.4.sh
# Install gcc 10
#RUN dnf -y install wget unzip lbzip2\
# && dnf -y groupinstall "Development Tools"\
# && cd /usr/local/src\
# && wget https://github.com/gcc-mirror/gcc/archive/refs/heads/releases/gcc-10.zip\
# && unzip gcc-10.zip\
# && cd gcc-releases-gcc-10\
# && contrib/download_prerequisites\
# && mkdir /usr/local/gcc-10\
# && cd /usr/local/gcc-10\
# && /usr/local/src/gcc-releases-gcc-10/configure --disable-multilib\
# && make -j ${nproc}\
# && make install
RUN dnf install -y gcc-toolset-10-gcc gcc-toolset-10-gcc-c++ gcc-toolset-10-runtime
# Post install, setup path
#COPY gcc-10.sh /etc/profile.d/gcc-10.sh
#COPY gcc-10.sh /etc/ld.so.conf.d/gcc-10.conf
#RUN scl enable gcc-toolset-10 bash
# Install cmake
#ENV LD_LIBRARY_PATH="/usr/local/lib64:/usr/local/cuda-11.4/lib64"
#ENV PATH="/usr/local/cuda-11.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
#RUN dnf -y install openssl-devel\
# && cd /usr/local/src\
# && wget https://github.com/Kitware/CMake/releases/download/v4.0.0/cmake-4.0.0.tar.gz\
# && tar xvf cmake-4.0.0.tar.gz\
# && mkdir /usr/local/cmake-4\
# && cd /usr/local/cmake-4\
# && /usr/local/src/cmake-4.0.0/configure\
# && make -j ${nproc}\
# && make install
RUN dnf -y install cmake
# Install go
#RUN cd /usr/local\
# && wget https://go.dev/dl/go1.24.2.linux-amd64.tar.gz\
# && tar xvf go1.24.2.linux-amd64.tar.gz
RUN dnf -y install golang
# Post install, setup path
#COPY go-1.24.2.sh /etc/profile.d/go-1.24.2.sh
#ENV PATH="$PATH:/usr/local/go/bin"

58
docker/builder/README.md Normal file
View File

@@ -0,0 +1,58 @@
# Ollama37 Builder Image
This directory contains the Dockerfile for building the `ollama37-builder:latest` image.
## What's Inside
The builder image includes:
- **Base**: `nvidia/cuda:11.4.3-devel-rockylinux8`
- **GCC 10**: `gcc-toolset-10` (required by CUDA 11.4)
- **CMake**: System package
- **Go**: System package
## Building the Builder Image
The builder image is **automatically built** by the Makefile when you run `make build` for the first time.
To manually build the builder image:
```bash
cd /home/jack/Documents/ollama37/docker
make build-builder
```
Or using Docker directly:
```bash
cd /home/jack/Documents/ollama37/docker/builder
docker build -t ollama37-builder:latest .
```
## Using the Builder Image
The Makefile handles this automatically, but for reference:
```bash
# Start builder container with GPU access
docker run --rm -d \
--name ollama37-builder \
--runtime=nvidia \
--gpus all \
ollama37-builder:latest \
sleep infinity
# Use the container
docker exec -it ollama37-builder bash
```
## Customization
If you need to modify the builder (e.g., change CUDA version, add packages):
1. Edit `Dockerfile` in this directory
2. Rebuild: `make clean-builder build-builder`
3. Build your project: `make build`
## Archived Builder
The `archived/` subdirectory contains an older Dockerfile that built GCC and CMake from source (~80 minutes). The current version uses Rocky Linux system packages for much faster builds (~5 minutes).