我正在将 Amazon ECR(Docker)条目中的节点设置从 更改node 14 x64
为。node 14 arm64
当我使用这个图像时,它构建没有问题:FROM aws/lambda/nodejs:14
并且这个命令来安装 sharpRUN npm install --platform=linux sharp
现在我需要使用Node 14 arm64
图像,但是在使用 Sharp JS(Linux arm 64)构建时会出现此错误:
Dockerfile:
FROM public.ecr.aws/lambda/nodejs:14-arm64
# Exec commands
COPY index.js package.json ${LAMBDA_TASK_ROOT}
COPY fonts ${LAMBDA_TASK_ROOT}/fonts/
COPY src ${LAMBDA_TASK_ROOT}/src/
# Commands
RUN npm cache clean --force
RUN rm -rf node_modules
RUN npm install --arch=arm64 --platform=linux sharp
CMD ["index.handler"]
构建命令:
docker build -t my-project-v1 .
docker tag my-project-v1:latest {ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/my-project-v1:latest
docker push {ACCOUNT}.dkr.ecr.us-east-1.amazonaws.com/my-project-v1:latest
错误:
=> ERROR [6/8] RUN npm install 7.3s
------
> [6/8] RUN npm install:
#10 2.231 npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
#10 2.249 npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
#10 6.947
#10 6.947 > [email protected] install /var/task/node_modules/sharp
#10 6.947 > (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
#10 6.947
#10 7.046 sharp: Installation error: Use with glibc 2.26 requires manual installation of libvips >= 8.11.3
#10 7.046 sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
#10 7.172 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents):
#10 7.173 npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"arm64"})
#10 7.174
#10 7.234 npm ERR! code ELIFECYCLE
#10 7.235 npm ERR! errno 1
#10 7.242 npm ERR! [email protected] install: `(node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)`
#10 7.242 npm ERR! Exit status 1
#10 7.243 npm ERR!
#10 7.244 npm ERR! Failed at the [email protected] install script.
#10 7.244 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#10 7.261
#10 7.262 npm ERR! A complete log of this run can be found in:
#10 7.262 npm ERR! /root/.npm/_logs/2022-01-10T13_28_10_709Z-debug.lo
答案1
错误消息表明问题与以下内容有关libvips
:sharp: Installation error: Use with glibc 2.26 requires manual installation of libvips >= 8.11.3
。在官方锐利文档我发现在 Linux x64 以外的机器上(例如您的情况:Linux arm64),您应该忽略全局libvips
更新SHARP_IGNORE_GLOBAL_LIBVIPS
环境变量:
npm install
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux sharp
因此,您应该将您的更新Dockerfile
如下:
FROM public.ecr.aws/lambda/nodejs:14-arm64
# Exec commands
COPY index.js package.json ${LAMBDA_TASK_ROOT}
COPY fonts ${LAMBDA_TASK_ROOT}/fonts/
COPY src ${LAMBDA_TASK_ROOT}/src/
# Commands
RUN npm cache clean --force
RUN rm -rf node_modules
## update the dockerfile with the following lines:
RUN npm install
RUN SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux sharp
CMD ["index.handler"]