Google Cloud Run | Angular项目部署为无服务器容器COPY失败:未指定源文件

时间:2019-09-18 12:23:16

标签: docker nginx

  1. 环境:Google云运行
  2. 项目:Angular 8
  3. 部署类型:无服务器容器
  4. 从Windows 10 Pro PC创建Linux容器
  5. 这是我下面的cloudbuild.yaml文件:
steps:

  # build the container image
  - name: gcr.io/cloud-builders/docker
    args: [ build, -t, gcr.io/<project name here>/<container name here>, . ]

  # push the container image to Container Registry
  - name: gcr.io/cloud-builders/docker
    args: [ push, gcr.io/<project name here>/<container name here> ]

  # Deploy container image to Cloud Run
  - name: gcr.io/cloud-builders/gcloud
    args: [ beta, run, deploy, <container name here>, --image, gcr.io/<project name here>/<container name here>, --platform, managed, --region, us-central1 ]


images:

- gcr.io/<project name here>/<container name here>
  1. 以下是我的Dockerfile:
FROM node:10.9-alpine AS build-stage
WORKDIR /app
COPY . .
RUN npm install && npm run build --prod

FROM nginx:latest
COPY /etc/nginx/*.conf /etc/nginx/

## Create the new /var/logs/nginx folder
RUN mkdir /var/logs
RUN mkdir /var/logs/nginx
## Copy a new configuration file setting listen port to 8080
COPY /etc/nginx/conf.d/*.conf /etc/nginx/conf.d/
## Expose port 8080
EXPOSE 8080
## Remove default nginx website
RUN rm -rf /usr/share/nginx/html/*
## From 'build' stage copy over the artifacts in dist folder to default nginx public folder
COPY --from=build-stage /app/dist/* /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
  1. 这是我的.dockerignore文件
# Node
node_modules/

# Angular
dist/
  1. 这是我在nginx下面的错误
Step #0: Step 6/13 : COPY /etc/nginx/*.conf /etc/nginx/
Step #0: COPY failed: no source files were specified
Finished Step #0
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ERROR: (gcloud.builds.submit) build 731c37fb-f282-4649-972e-aec572b33bca completed with status "FAILURE"

我在这里想念什么?任何线索都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

据此:

Step #0: Step 6/13 : COPY /etc/nginx/*.conf /etc/nginx/
Step #0: COPY failed: no source files were specified

问题是您使用COPY命令。使用COPY /etc/nginx/*.conf /etc/nginx/时,应确保要复制的文件在构建上下文中。因此,您应该做的是确保* .conf文件位于正确的目录中。它应该看起来像这样:

/etc/nginx/*.conf
/etc/Dockerfile

或者这样:

/etc/nginx/folderName/*.conf
/etc/nginx/Dockerfile

另一种方法是使用VOLUME而不是COPYVOLUME的作用是将所需目录装载到容器内的目录。它本身不会复制文件,而是创建对实际目录的“引用”。

安装音量(-v,-只读)

$ docker  run  -v `pwd`:`pwd` -w `pwd` -i -t  ubuntu pwd

-v标志将当前工作目录安装到容器中。 -w通过将目录更改为pwd返回的值,使命令在当前工作目录中执行。因此,此组合使用容器在当前工作目录中执行命令。

一些有关Dockerfile的有用链接:

Dockerfile reference

Best Practices

Docker run

请告诉我这是否有帮助。