- 环境:谷歌云运行
- 项目 : 角度 8
- 部署类型 : 无服务器容器
- 从 Windows 10 专业版 PC 创建 Linux 容器
- 这是我下面的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>
- 这是我下面的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;"]
- 这是我的 .dockerignore 文件
# Node
node_modules/
# Angular
dist/
- 这是我下面来自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"
我在这里错过了什么? 任何线索都受到高度赞赏。
根据这个:
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
而不是COPY
.VOLUME
所做的是将您想要的目录挂载到容器内的目录中。它不会复制文件本身,而是创建对实际目录的"引用"。
装入卷(-v、--只读(
$ docker run -v `pwd`:`pwd` -w `pwd` -i -t ubuntu pwd
-v
标志将当前工作目录挂载到容器中。-w
允许命令在当前工作目录中执行,方法是将目录更改为pwd
返回的值。因此,此组合使用容器执行命令,但在当前工作目录中。
关于 Dockerfiles 的一些有用链接:
Dockerfile 参考
最佳实践
码头工人运行
如果这有帮助,请告诉我。