Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 22e344b

Browse files
authored
feat: Dockerfile (#1473)
Co-authored-by: Hien To <tominhhien97@gmail.com>
1 parent 10b64ee commit 22e344b

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed

docker/Dockerfile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
FROM ubuntu:22.04 as base
2+
3+
FROM base as build
4+
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Install dependencies
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
ca-certificates \
10+
curl \
11+
wget \
12+
jq \
13+
tar \
14+
openmpi-bin \
15+
libopenmpi-dev && \
16+
apt-get clean && \
17+
rm -rf /var/lib/apt/lists/*
18+
19+
RUN apt-get update && apt-get install -y --no-install-recommends \
20+
git \
21+
uuid-dev \
22+
lsb-release \
23+
software-properties-common \
24+
gpg \
25+
zip \
26+
unzip \
27+
gcc \
28+
g++ \
29+
ninja-build \
30+
pkg-config \
31+
openssl && \
32+
apt-get clean && \
33+
rm -rf /var/lib/apt/lists/*
34+
35+
RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \
36+
apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" && \
37+
apt-get update && \
38+
apt-get install -y cmake && \
39+
apt-get clean && \
40+
rm -rf /var/lib/apt/lists/*
41+
42+
WORKDIR /app
43+
44+
COPY . /app/
45+
46+
RUN git submodule update --init && cd engine && make configure-vcpkg && make build CMAKE_EXTRA_FLAGS="-DCORTEX_CPP_VERSION=$(git rev-parse HEAD) -DCMAKE_BUILD_TEST=OFF -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake"
47+
48+
FROM base as runtime
49+
50+
ENV DEBIAN_FRONTEND=noninteractive
51+
52+
# Install dependencies
53+
RUN apt-get update && apt-get install -y --no-install-recommends \
54+
ca-certificates \
55+
curl \
56+
wget \
57+
jq \
58+
tar \
59+
openmpi-bin \
60+
libopenmpi-dev && \
61+
apt-get clean && \
62+
rm -rf /var/lib/apt/lists/*
63+
64+
ARG CORTEX_LLAMACPP_VERSION=latest
65+
66+
COPY --from=build /app/engine/build/cortex /usr/local/bin/cortex
67+
COPY --from=build /app/engine/build/cortex-server /usr/local/bin/cortex-server
68+
69+
COPY ./docker/download-cortex.llamacpp.sh /tmp/download-cortex.llamacpp.sh
70+
71+
# Get the latest version of the Cortex Llama
72+
RUN chmod +x /tmp/download-cortex.llamacpp.sh && /bin/bash /tmp/download-cortex.llamacpp.sh ${CORTEX_LLAMACPP_VERSION}
73+
74+
# Copy the entrypoint script
75+
COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
76+
77+
EXPOSE 39281
78+
79+
HEALTHCHECK --interval=300s --timeout=30s --start-period=10s --retries=3 \
80+
CMD curl -f http://127.0.0.1:39281/healthz || exit 1
81+
82+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

docker/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Cortex Docker Setup
2+
3+
This guide will help you set up and run Cortex using Docker.
4+
5+
### Prerequisites
6+
- Docker / Docker Desktop
7+
- nvidia-container-toolkit (for GPU support)
8+
9+
### Instructions
10+
1. Clone the Cortex repository
11+
```bash
12+
git clone https://github.com/janhq/cortex.cpp.git
13+
14+
cd cortex.cpp/docker
15+
```
16+
2. Build the Docker image
17+
```bash
18+
# Default always uses the latest cortex.cpp and cortex.llamacpp
19+
docker build -t cortex .
20+
21+
# Use specific version of cortex.cpp and cortex.llamacpp
22+
docker build --build-arg CORTEX_LLAMACPP_VERSION=0.1.34 -t cortex .
23+
```
24+
25+
3. Run the Docker container
26+
```bash
27+
# Create Volume to store models and data
28+
docker volume create cortex_data
29+
30+
# CPU mode
31+
docker run -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 cortex
32+
33+
# GPU mode - nvidia-docker required, it will automatically use all available GPUs
34+
docker run --gpus all -it -d --name cortex -v cortex_data:/root/cortexcpp -p 39281:39281 cortex
35+
```
36+
37+
4. Check logs (Optional)
38+
```bash
39+
docker logs cortex
40+
```
41+
42+
5. Access to http://localhost:39281 to check the cortex docs API.
43+
44+
6. Execute to container and try out cortex cli
45+
```bash
46+
docker exec -it cortex bash
47+
cortex --help
48+
```

docker/download-cortex.llamacpp.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
VERSION=${1:-latest}
4+
5+
# Get the latest version of the cortex.llamacpp
6+
if [ "$VERSION" = "latest" ]; then
7+
VERSION=$(curl -s https://api.github.com/repos/janhq/cortex.llamacpp/releases/latest | jq -r '.tag_name' | sed 's/^v//');
8+
fi
9+
10+
# Create the directory to store the cortex.llamacpp
11+
mkdir -p /opt/cortex.llamacpp
12+
cd /opt/cortex.llamacpp
13+
14+
# Download the cortex.llamacpp engines
15+
echo -e "Downloading Cortex Llama version $VERSION"
16+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx-cuda-11-7.tar.gz
17+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx-cuda-12-0.tar.gz
18+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx.tar.gz
19+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx2-cuda-11-7.tar.gz
20+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx2-cuda-12-0.tar.gz
21+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx2.tar.gz
22+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx512-cuda-11-7.tar.gz
23+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx512-cuda-12-0.tar.gz
24+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-avx512.tar.gz
25+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-noavx-cuda-11-7.tar.gz
26+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-noavx-cuda-12-0.tar.gz
27+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-noavx.tar.gz
28+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cortex.llamacpp-$VERSION-linux-amd64-vulkan.tar.gz
29+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cuda-11-7-linux-amd64.tar.gz
30+
wget https://github.com/janhq/cortex.llamacpp/releases/download/v$VERSION/cuda-12-0-linux-amd64.tar.gz

docker/entrypoint.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
# Install cortex.llamacpp engine
4+
5+
cortex engines install llama-cpp -s /opt/cortex.llamacpp
6+
cortex -v
7+
8+
# Start the cortex server
9+
10+
sed -i 's/apiServerHost: 127.0.0.1/apiServerHost: 0.0.0.0/' /root/.cortexrc
11+
12+
cortex start
13+
14+
# Keep the container running by tailing the log files
15+
tail -f /root/cortexcpp/logs/cortex.log &
16+
tail -f /root/cortexcpp/logs/cortex-cli.log &
17+
wait

0 commit comments

Comments
 (0)