【问题标题】:Missing file in my Dockerfile, whats the path its running from?我的 Dockerfile 中缺少文件,它的运行路径是什么?
【发布时间】: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 build manual)。在大多数情况下,我们使用.,即当前目录,作为构建上下文。这是用于解析 Dockerfile 中定义 docker-host 资源的所有路径的路径。
  • 我已经添加了构建镜像的命令

标签: docker dockerfile github-actions


【解决方案1】:

WORKDIR 指的是容器中的工作目录。主机上的工作目录仍然是你的 repo 的根目录。

【讨论】:

  • "主机上的工作目录仍然是你的 repo 的根目录。" - 这是一个假设 :) 只要我们没有看到 docker build ... 命令,我们无法确定上下文目录是什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-01
  • 2018-07-07
  • 1970-01-01
  • 2013-01-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多