微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

node.js – Docker COPY问题 – “没有这样的文件或目录”

在我的Dockerfile中,我有以下’copY’语句:

# copy app code
copY /srv/visitor /srv/visitor

不言而喻,在我的主机系统中,在“/ srv / visitor”目录下,确实有我的源代码

[root@V12 visitor]# ls /srv/visitor/
Dockerfile  package.json  visitor.js

现在,当我尝试使用这个Dockerfile构建一个图像时,它会挂起“copY”应该发生的步骤:

Step 10 : copY /srv/visitor /srv/visitor
INFO[0155] srv/visitor: no such file or directory

它说没有这样的目录,但显然有.

有任何想法吗?

更新1:

有人指出我错了,就像我理解构建语境一样.该建议相当于将“copY”声明更改为:

copY . /srv/visitor

问题是我有这种方式,并且构建过程在下一步停止:

RUN npm install

它说的是“没有找到package.json文件”的内容,当时显然有一个.

更新2:

我尝试在Dockerfile中使用此更改运行它:

copY source /srv/visitor/

尝试运行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

那么,副本是否已执行?如果是的话,为什么npm无法找到package.json?

解决方法

从文档:

The <src> path must be inside the context of the build; you cannot copY ../something /something,because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

当您使用/ srv / visitor时,即使它实际上是当前目录,您也在构建上下文之外使用绝对路径.

您最好像这样组织构建上下文:

├── /srv/visitor
│   ├── Dockerfile
│   └── resources
│       ├── visitor.json
│       ├── visitor.js

并使用:

copY resources /srv/visitor/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐