【问题标题】:Build NextJS Docker image with nginx server使用 nginx 服务器构建 NextJS Docker 映像
【发布时间】:2021-04-29 21:28:15
【问题描述】:

我是 docker 新手,并试图通过 documentation 来学习它。因为我需要使用 docker 镜像为 nginx 服务器创建 NextJS 构建,所以我遵循了以下过程。

  1. 安装nginx
  2. Seeding the port 80 to 3000 in the default config
  3. out 目录符号链接到基础 nginx 目录
  4. CMD 负责输出目录的生产构建和符号链接。
FROM node:alpine AS deps

RUN apk add --no-cache libc6-compat git
RUN apt-get install nginx -y

WORKDIR /sample-app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

FROM node:alpine AS builder
WORKDIR /sample-app
COPY . .
COPY --from=deps /sample-app/node_modules ./node_modules
RUN yarn build

FROM node:alpine AS runner
WORKDIR /sample-app

ENV NODE_ENV production

RUN ls -SF /sample-app/out /usr/share/nginx/html
RUN -p 3000:80 -v /sample-app/out:/usr/share/nginx/html:ro -d nginx
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
RUN chown -R nextjs:nodejs /sample-app/out
USER nextjs

CMD ["nginx -g daemon=off"]

在以sudo docker build . -t sample-app 运行 docker build shell 脚本命令时,它会抛出错误 The command '/bin/sh -c apt-get install nginx -y' returned a non-zero code: 127

【问题讨论】:

  • 如果您仍然要安装 GNU libc,请考虑使用基于 Debian 或 Ubuntu 的映像,而不是 Alpine。对于最终图像,还可以考虑重用标准nginx 图像;将应用程序编译为静态文件后,您就不需要在其中包含 Node。

标签: docker nginx next.js


【解决方案1】:

我对 alpine 映像没有太多经验,但我认为您必须使用 apk (Alpine Package Keeper) 来安装软件包

尝试apk add nginx 而不是apt-get install nginx -y

【讨论】:

  • 谢谢,它可以工作,但符号链接现在抛出错误。命令“/bin/sh -c ls -SF /sample-app/out /usr/share/nginx/html”返回非零代码:1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-20
  • 1970-01-01
  • 2019-07-05
相关资源
最近更新 更多