fix: 容器内以 root 运行以访问 Docker socket,docker compose 改为 docker-compose

This commit is contained in:
2026-05-24 23:20:29 +08:00
parent dbdd055420
commit 375a0453ae
2 changed files with 6 additions and 4 deletions
+4 -2
View File
@@ -54,8 +54,10 @@ RUN chown -R nextjs:nodejs /app
# 安装 git(版本检查、拉取更新)和 docker CLI(构建/重启容器) # 安装 git(版本检查、拉取更新)和 docker CLI(构建/重启容器)
USER root USER root
RUN apk add --no-cache git docker-cli docker-compose RUN apk add --no-cache git docker-cli docker-compose
RUN chown -R nextjs:nodejs /app # 以 root 运行以确保有权限访问挂载的 Docker socket /var/run/docker.sock
USER nextjs # 若需以非 root 运行,需在宿主机上执行:
# sudo chmod 666 /var/run/docker.sock
# 或在容器入口脚本中动态匹配 socket 的 group GID
EXPOSE 3000 EXPOSE 3000
ENV PORT=3000 ENV PORT=3000
+2 -2
View File
@@ -297,7 +297,7 @@ export async function executeUpdate(
// 3. 构建新镜像 // 3. 构建新镜像
onLog("[3/4] 构建新 Docker 镜像"); onLog("[3/4] 构建新 Docker 镜像");
execSync(`cd "${tmpDir}" && docker compose -p recipe_tool build`, { execSync(`cd "${tmpDir}" && docker-compose -p recipe_tool build`, {
encoding: "utf-8", encoding: "utf-8",
timeout: 600000, timeout: 600000,
windowsHide: true, windowsHide: true,
@@ -307,7 +307,7 @@ export async function executeUpdate(
// 4. 重启服务 // 4. 重启服务
onLog("[4/4] 重启服务"); onLog("[4/4] 重启服务");
execSync(`cd "${tmpDir}" && docker compose -p recipe_tool up -d`, { execSync(`cd "${tmpDir}" && docker-compose -p recipe_tool up -d`, {
encoding: "utf-8", encoding: "utf-8",
timeout: 60000, timeout: 60000,
windowsHide: true, windowsHide: true,