使用 Docker 编译 StarRocks
本文介绍如何使用 Docker 编译 StarRocks。
概述
StarRocks 提供了 Ubuntu 22.04 和 CentOS 7.9 的开发环境镜像。通过该镜像,您可以启动 Docker 容器并在容器中编译 StarRocks。
StarRocks 版本和 DEV ENV 镜像
StarRocks 的不同分支对应于 StarRocks Docker Hub 上提供的不同开发环境镜像。
-
对于 Ubuntu 22.04
分支名称 镜像名称 main starrocks/dev-env-ubuntu:latest branch-3.5 starrocks/dev-env-ubuntu:3.5-latest branch-3.4 starrocks/dev-env-ubuntu:3.4-latest branch-3.3 starrocks/dev-env-ubuntu:3.3-latest branch-3.2 starrocks/dev-env-ubuntu:3.2-latest branch-3.1 starrocks/dev-env-ubuntu:3.1-latest branch-3.0 starrocks/dev-env-ubuntu:3.0-latest branch-2.5 starrocks/dev-env-ubuntu:2.5-latest -
对于 CentOS 7.9
分支名称 镜像名称 main starrocks/dev-env-centos7:latest branch-3.5 starrocks/dev-env-centos7:3.5-latest branch-3.4 starrocks/dev-env-centos7:3.4-latest branch-3.3 starrocks/dev-env-centos7:3.3-latest branch-3.2 starrocks/dev-env-centos7:3.2-latest branch-3.1 starrocks/dev-env-centos7:3.1-latest branch-3.0 starrocks/dev-env-centos7:3.0-latest branch-2.5 starrocks/dev-env-centos7:2.5-latest
前提条件
在编译 StarRocks 之前,请确保满足以下要求
-
硬件
您的机器必须至少有 8 GB 内存。
-
软件
- 您的机器必须运行在 Ubuntu 22.04 或 CentOS 7.9 上。
- 您必须在机器上安装 Docker,且版本至少为 v20.10.10。
步骤 1:下载镜像
运行以下命令下载开发环境镜像
# Replace <image_name> with the name of the image that you want to download,
# for example, `starrocks/dev-env-ubuntu:latest`.
# Make sure you have choose the correct image for your OS.
docker pull <image_name>
Docker 会自动识别您机器的 CPU 架构,并拉取适合您机器的相应镜像。linux/amd64
镜像适用于基于 x86 的 CPU,而 linux/arm64
镜像适用于基于 ARM 的 CPU。
步骤 2:在 Docker 容器中编译 StarRocks
您可以在启动开发环境 Docker 容器时挂载或不挂载本地主机路径。 我们建议您启动容器时挂载本地主机路径,这样可以避免下次编译时重新下载 Java 依赖,并且无需手动将二进制文件从容器复制到本地主机。
-
启动容器时挂载本地主机路径:
-
将 StarRocks 源代码克隆到您的本地主机。
git clone https://github.com/StarRocks/starrocks.git
-
启动容器。
# Replace <code_dir> with the parent directory of the StarRocks source code directory.
# Replace <branch_name> with the name of the branch that corresponds to the image name.
# Replace <image_name> with the name of the image that you downloaded.
docker run -it -v <code_dir>/.m2:/root/.m2 \
-v <code_dir>/starrocks:/root/starrocks \
--name <branch_name> -d <image_name> -
在您启动的容器内启动一个 bash shell。
# Replace <branch_name> with the name of the branch that corresponds to the image name.
docker exec -it <branch_name> /bin/bash -
在容器中编译 StarRocks。
cd /root/starrocks && ./build.sh
-
-
启动容器时不挂载本地主机路径:
-
启动容器。
# Replace <branch_name> with the name of the branch that corresponds to the image name.
# Replace <image_name> with the name of the image that you downloaded.
docker run -it --name <branch_name> -d <image_name> -
在容器内启动一个 bash shell。
# Replace <branch_name> with the name of the branch that corresponds to the image name.
docker exec -it <branch_name> /bin/bash -
将 StarRocks 源代码克隆到容器中。
git clone https://github.com/StarRocks/starrocks.git
-
在容器中编译 StarRocks。
cd starrocks && ./build.sh
-
问题排查
问:StarRocks BE 构建失败,并返回以下错误消息
g++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
我该怎么办?
答:此错误消息表明 Docker 容器中内存不足。 您需要为容器分配至少 8 GB 的内存资源。