docker打包npm问题

打包命令:
docker build -t demo-fraud-webapp:latest -f webapp/webapp.Dockerfile webapp/
提示错误信息:

#17 187.1 > [email protected] postinstall /home/node/app
#17 187.1 > ./scripts/fix-leader-line.sh
#17 187.1
#17 187.1 sh: 1: ./scripts/fix-leader-line.sh: not found
#17 187.1 npm ERR! code ELIFECYCLE
#17 187.1 npm ERR! syscall spawn
#17 187.1 npm ERR! file sh
#17 187.1 npm ERR! errno ENOENT
#17 187.1 npm ERR! [email protected] postinstall: `./scripts/fix-leader-line.sh`
#17 187.1 npm ERR! spawn ENOENT
#17 187.1 npm ERR!
#17 187.1 npm ERR! Failed at the [email protected] postinstall script.
#17 187.1 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#17 187.1
#17 187.1 npm ERR! A complete log of this run can be found in:
#17 187.1 npm ERR!     /root/.npm/_logs/2021-09-12T06_36_08_995Z-debug.log
------
executor failed running [/bin/sh -c npm ci --unsafe-perm]: exit code: 1

webapp.Dockerfile内容:

# --- UI Build
FROM node:10 as ui-build
WORKDIR /home/node/app

COPY package.json package-lock.json tsconfig.json ./
COPY scripts scripts
RUN npm ci --unsafe-perm  # 运行到该命令出错
COPY public public
COPY src/app src/app
COPY src/index.tsx src
COPY src/react-app-env.d.ts src
RUN npm run build

开始以为是不存在文件scripts/fix-leader-line.sh
接着进入docker交互模式,手动把文件上传容器中:

docker cp .\scripts\ 4298535f77cc:/home/node/app/scripts/ 

重新执行:npm ci --unsafe-perm

仍报该错误,根据打印信息进到日志文件/root/.npm/_logs/2021-09-12T06_36_08_995Z-debug.log
错误信息:

16733 verbose pkgid [email protected]
16734 verbose cwd /home/node/app
16735 verbose Linux 5.4.72-microsoft-standard-WSL2
16736 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "ci" "--unsafe-perm"
16737 verbose node v10.24.1
16738 verbose npm  v6.14.12
16739 error code ELIFECYCLE
16740 error syscall spawn
16741 error file sh
16742 error errno ENOENT
16743 error [email protected] postinstall: `./scripts/fix-leader-line.sh`
16743 error spawn ENOENT
16744 error Failed at the [email protected] postinstall script.
16744 error This is probably not a problem with npm. There is likely additional logging output above.
16745 verbose exit [ 1, true ]

猜测是上传的文件使用的CRLF格式导致,使用Idea转为LF,重新上传,重新打包,问题解决!

你可能感兴趣的:(docker打包npm问题)