【发布时间】:2021-12-20 08:46:03
【问题描述】:
我的 git repo 结构
app
- app.server
- server files
- app.client
- node_modules
- public
- src
- .dockerignore
- Dockerfile
- package.json
- package-log.json
我已使用 GitHub 操作设置 CI/CD,但我的客户端应用程序 (React) 的 Dockerimage 中有问题?
错误信息:COPY failed: file not found in build context or excluded by .dockerignore: stat package.json: file does not exist
我的 .dockeringore 文件:
node_modules
build
.dockerignore
Dockerfile
Dockerfile.prod
我的 Dockerfile:
# pull official base image
FROM node:13.12.0-alpine
# set working directory
WORKDIR /app.client
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app.client/node_modules/.bin:$PATH
# install app dependencies
COPY package.json ./
COPY package-lock.json ./
RUN npm install --silent
RUN npm install react-scripts@3.4.1 -g --silent
# add app
COPY ./ ./
# start app
CMD ["npm", "start"]
我用于调用 Dockerfile 的 GitHub 操作命令:
docker build app.client/ -t mycontainerregistry.azurecr.io/appdb:${{ github.sha }}
这是我正在尝试学习的发布到 Azure 容器注册表的一部分。我猜 Dockerfile 可以工作,因为在第 4/9 步失败之前,它会通过 Dockerfile:
Step 1/9 : FROM node:13.12.0-alpine
13.12.0-alpine: Pulling from library/node
aad63a933944: Pulling fs layer
... (and so on)
Step 3/6 : COPY package.json ./
COPY failed: file not found in build context or excluded by .dockerignore: stat package.json: file does not exist
Error: Process completed with exit code 1.
【问题讨论】:
-
你是如何建立你的形象的?
-
.dockerignore包含什么(忽略)? -
如何调用 docker?看起来您不在正确的目录中。最好通过使用一些指向 repo 作为上下文的管道变量来明确说明,而不仅仅是一个点或其他东西。
-
"它的运行路径是什么?" -
docker build ...命令的最后一个参数是路径、URL 或-,并指定构建上下文(参见docker buildmanual)。在大多数情况下,我们使用.,即当前目录,作为构建上下文。这是用于解析 Dockerfile 中定义 docker-host 资源的所有路径的路径。 -
我已经添加了构建镜像的命令
标签: docker dockerfile github-actions