我创建了一个 Dockerfile 来运行一个简单的 Vue.js SPA,使用lighttpd作为网络服务器。
Dockerfile
FROM node:fermium-alpine AS builder
RUN apk update && \
apk add --no-cache \
git && \
rm -rf /var/cache/apk/*
WORKDIR /app
COPY package*.json ./
RUN npm set progress=false && \
npm config set depth 0 && \
npm ci
COPY . .
RUN npm run build
FROM alpine
RUN apk update && \
apk add --no-cache \
lighttpd \
curl && \
rm -rf /var/cache/apk/*
COPY ./support/lighttpd/*.conf /etc/lighttpd/
HEALTHCHECK --interval=1m --timeout=1s CMD curl -f http://localhost/ || exit 1
COPY --from=builder /app/dist/ /var/www/localhost/htdocs/
EXPOSE 80
ENTRYPOINT ["/usr/sbin/lighttpd", "-D", "-f", "/etc/lighttpd/lighttpd.conf"]
(修改了 lighttpd 配置以将未找到的路由重定向回应用程序,以便pushState
可以使用导航,并添加了一行:server.error-handler-404 = "/index.html"
。)
当我直接在 Docker Desktop for Windows 中构建这个容器时,它运行良好,但是当我使用 Kaniko(由 GitLab CI 在 Docker Desktop for Mac 中运行)构建它时,当我尝试运行容器时出现以下错误:
2020-12-11 05:39:25: (server.c.752) opening errorlog '/var/log/lighttpd/error.log' failed: Permission denied
2020-12-11 05:39:25: (server.c.1485) Opening errorlog failed. Going down.
当我比较容器时,我看到以下差异:
Docker 桌面构建
/ # ls -la /var/log/lighttpd/
total 8
drwxr-s--- 2 lighttpd wheel 4096 Dec 11 04:26 .
drwxr-xr-x 1 root root 4096 Dec 11 04:26 ..
Kaniko建造
/ # ls -la /var/log/lighttpd/
total 8
drwxr-xr-x 2 root root 4096 Dec 11 04:51 .
drwxr-xr-x 1 root root 4096 Dec 11 04:51 ..
为什么 Kaniko 构建的容器对日志目录有错误的权限?