thingsboard/summary/10-如何构建Docker镜像.md

76 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 如何构建 ThingsBoard Docker 镜像
## 问题说明
### build.sh 的默认行为
查看 `build.sh` 第 34 行:
```bash
mvn -T2 license:format clean install -DskipTests \
$PROJECTS --also-make
```
**注意**:这里**没有** `-Ddockerfile.skip=false` 参数!
### 默认配置
查看 `msa/pom.xml` 第 35 行:
```xml
<dockerfile.skip>true</dockerfile.skip>
```
**这意味着默认情况下Docker 镜像构建是跳过的!**
## 为什么默认跳过 Docker 构建?
1. **构建时间长**: Docker 镜像构建需要很长时间
2. **需要 Docker**: 不是所有环境都有 Docker
3. **日常开发**: 大多数时候只需要编译代码,不需要镜像
## 如何启用 Docker 镜像构建
### 方法1直接使用 Maven 命令(推荐)
```bash
# 构建所有项目并构建 Docker 镜像
MAVEN_OPTS="-Xmx2048m" \
NODE_OPTIONS="--max_old_space_size=4096" \
DOCKER_CLI_EXPERIMENTAL=enabled \
DOCKER_BUILDKIT=0 \
mvn -T2 license:format clean install -DskipTests \
-Ddockerfile.skip=false \
--also-make
```
### 方法2修改 build.sh临时
可以临时修改 `build.sh`,在第 34 行添加 `-Ddockerfile.skip=false`
```bash
mvn -T2 license:format clean install -DskipTests \
-Ddockerfile.skip=false \
$PROJECTS --also-make
```
然后执行:
```bash
./build.sh
```
### 方法3构建特定模块的镜像
```bash
# 只构建 tb-node 的 Docker 镜像
mvn clean install -DskipTests \
-Ddockerfile.skip=false \
--projects msa/tb-node \
--also-make
```
## 构建 Docker 镜像的命令
让我为您执行构建命令: