feat(docker): 将 APP_VERSION 构建进镜像,解决 Watchtower 更新后版本号显示不准的问题 #200
Reference in New Issue
Block a user
Delete Branch "feat/app-version-in-dockerfile"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题
当前 APP_VERSION 是容器启动时注入的环境变量,Watchtower 更新镜像时会保留旧容器的环境变量配置,导致版本号一直显示旧值(虽然代码实际已更新)。
解决方案
将 APP_VERSION 通过 --build-arg 在构建时传入,并用 ENV 固化到镜像中。这样 Watchtower 更新镜像后,版本号自动同步为新镜像的构建版本。
修改内容
ARG APP_VERSION=dev和ENV APP_VERSION=$APP_VERSION--build-arg APP_VERSION=$VERSION影响
dev,本地构建不受影响