我正在尝试从Gitlab管道中的Dockerfile复制映像构建。当我在机器上本地使用docker时,我没有问题。但是,当我尝试在管道中复制进程时,脚本将失败,并显示以下错误:
Step 6/12 : RUN npm run-script build
---> Running in 4717c4b9d61a
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /app/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
这是我的.gitlab-ci.yml
image: docker:18.09.7
services:
- docker:18.09.7-dind
stages:
- build
- test
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE -f ./hackapp/Dockerfile
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
build:
stage: build
script:
- docker build -t $IMAGE_TAG .
- docker push $IMAGE_TAG
test:
stage: test
services:
- mongo:bionic
script:
- docker pull $IMAGE_TAG
- docker run $IAMGE_TAG
还有我的Dockerfile
# Stage I
FROM node:stretch-slim AS react-build
WORKDIR /app
COPY . /app/
RUN npm install
RUN npm install react-scripts@3.0.1 -g
RUN npm run-script build
# Stage II
#Setup Nginx
FROM nginx:1.16.0-alpine
COPY --from=react-build /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
#Fire up Nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
我尝试在第一个npm install npm@latest -g
中安装添加RUN
,但是好像找不到package.json
文件的路径
答案 0 :(得分:1)
可能是package.json并未真正复制到/ app /目录中。您可以使用ls -l进行确认。