You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker环境下Zola CLI的--base-url参数无法正常生效问题排查

问题原因与解决方案

你的问题出在Dockerfile中RUN指令的执行格式上:

你当前使用的是exec数组格式的RUN命令:

RUN ["zola", "build", "--base-url", "$BASE_URL"]

这种模式下,Docker会直接执行指定的二进制文件(zola),不会通过shell来解析参数里的$BASE_URL变量,导致Zola收到的参数就是字符串$BASE_URL,而非你传入的实际值http://localhost:8000。

修复方案

有两种方式可以解决这个问题:

方案1:改用shell格式的RUN指令

直接去掉数组包裹,让shell负责变量解析:

# Stage 1: Build the site with Zola
FROM ghcr.io/getzola/zola:v0.20.0 AS build
ARG BASE_URL="https://example.com"
COPY . /project
WORKDIR /project
RUN zola build --base-url "$BASE_URL"

# Stage 2: Serve the site with Static Web Server
FROM ghcr.io/static-web-server/static-web-server:2 AS server
WORKDIR /
COPY --from=build /project/public /public

方案2:显式调用shell处理变量(保留exec格式)

如果一定要用exec数组格式,需要显式调用shell来解析变量:

RUN ["sh", "-c", "zola build --base-url \"$BASE_URL\""]

这里通过sh -c启动shell,让shell展开$BASE_URL变量后再执行zola命令。

验证

修改后重新执行docker compose build --no-cache,构建日志中依然会显示正确的参数传入,此时查看容器内的构建产物,get_url生成的路径会正确替换为实际的BASE_URL值。

内容的提问来源于stack exchange,提问作者Matthew Moran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 21:45:56