在我的 Dockerfile 中,我有以下“复制”语句:
# Copy app code
COPY /srv/visitor /srv/visitor
Run Code Online (Sandbox Code Playgroud)
不用说,在我的主机系统中,在“/srv/visitor”目录下,确实有我的源代码:
[root@V12 visitor]# ls /srv/visitor/
Dockerfile package.json visitor.js
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试使用此 Dockerfile 构建映像时,它会在应该发生“复制”的步骤中挂起:
Step 10 : COPY /srv/visitor /srv/visitor
INFO[0155] srv/visitor: no such file or directory
Run Code Online (Sandbox Code Playgroud)
它说没有这样的目录,但显然有。
有任何想法吗?
更新1:
有人指出我错了,因为我理解构建上下文的方式。该建议相当于将“COPY”语句更改为:
COPY . /srv/visitor
Run Code Online (Sandbox Code Playgroud)
问题是我是这样处理的,构建过程在下一步就停止了:
RUN npm install
Run Code Online (Sandbox Code Playgroud)
它说了一些类似“找不到 package.json 文件”的内容,但显然有一个。
更新 2:
我尝试在 Dockerfile 中使用此更改运行它:
COPY source /srv/visitor/
Run Code Online (Sandbox Code Playgroud)
尝试运行 npm 时它停止了:
Step 12 : RUN npm install
---> Running in ae5e2a993e11
npm ERR! install Couldn't read dependencies
npm ERR! Linux 3.18.5-1-ARCH
npm ERR! argv "/usr/bin/node" "/usr/sbin/npm" "install"
npm ERR! node v0.10.36
npm ERR! npm v2.5.0
npm ERR! path /package.json
npm ERR! code ENOPACKAGEJSON
npm ERR! errno 34
npm ERR! package.json ENOENT, open '/package.json'
npm ERR! package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directory.
npm ERR! Please include the following file with any support request:
npm ERR! /npm-debug.log
INFO[0171] The command [/bin/sh -c npm install] returned a non-zero code: 34
Run Code Online (Sandbox Code Playgroud)
那么,复制完成了吗?如果是,为什么 npm 找不到 package.json?
小智 48
对我来说,该目录位于正确的上下文中,只有它包含在.dockerignore项目根目录的(隐藏)文件中。这会导致错误消息:
lstat mydir/myfile.ext: no such file or directory
Run Code Online (Sandbox Code Playgroud)
Xav*_*cas 45
从文档:
该
<src>路径必须构建的上下文中; 您不能 COPY ../something /something,因为 docker 构建的第一步是将上下文目录(和子目录)发送到 docker 守护进程。
当您使用时,您使用/srv/visitor的是构建上下文之外的绝对路径,即使它实际上是当前目录。
你最好像这样组织你的构建上下文:
??? /srv/visitor
? ??? Dockerfile
? ??? resources
? ??? visitor.json
? ??? visitor.js
Run Code Online (Sandbox Code Playgroud)
并使用:
COPY resources /srv/visitor/
Run Code Online (Sandbox Code Playgroud)
笔记:
docker build - < Dockerfile 没有任何上下文。
因此使用,
docker build .
| 归档时间: |
|
| 查看次数: |
138163 次 |
| 最近记录: |