gpt4 book ai didi

Docker 无法使用复制命令找到文件或目录

转载 作者:行者123 更新时间:2023-12-02 18:29:48 25 4
gpt4 key购买 nike

所以我对 docker 还很陌生,它已经设置好了,但我已经用这个 dockerfile 搞砸了大约半个小时,试图为我拥有的 angular 6 应用程序获取一个工作图像。

除了困惑的 dockerfile 之外,最后一点似乎不起作用。所以我在 /workdir 目录中处理所有这些东西,构建我的角度应用程序等。之后我移到根目录,然后想复制 /workdir/dist 目录到根 /dist 文件夹,然后删除工作目录。我得到一个在复制行找不到的文件或目录。但是,如果我运行 ls,我会看到 workdir 存在,如果我运行 ls ./workdir/dist,我会看到其中有文件。

我对 linux 脚本和 docker 的理解非常有限,但我不明白为什么这似乎失败了。

FROM node:8
ENV ExposedPort 80
WORKDIR /workdir
COPY . /workdir
RUN npm install
RUN npm run production-angular
COPY package.json dist
COPY index.js dist
WORKDIR /
RUN ls
RUN ls workdir
RUN ls workdir/dist
COPY workdir/dist dist
CMD node index.js
EXPOSE ${ExposedPort}

我在 docker build 命令中的最后几行:

Step 9/15 : WORKDIR /
Removing intermediate container 10f69d248a51
---> d6184c6f0ceb
Step 10/15 : RUN ls
---> Running in c30b23783655
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
workdir
Removing intermediate container c30b23783655
---> fb74727468f6
Step 11/15 : RUN ls workdir
---> Running in e6bae18e3560
README.md
angular.json
dist
dockerfile
e2e
index.js
node_modules
package-lock.json
package.json
src
tsconfig.json
tslint.json
Removing intermediate container e6bae18e3560
---> c3e1f9f77d00
Step 12/15 : RUN ls workdir/dist
---> Running in 07923b11226e
3rdpartylicenses.txt
favicon.ico
index.html
index.js
main.1c74cb5a2b3da54e1148.js
package.json
polyfills.479875dfe4ba221bc297.js
runtime.a66f828dca56eeb90e02.js
styles.34c57ab7888ec1573f9c.css
Removing intermediate container 07923b11226e
---> 66ef563ba292
Step 13/15 : COPY workdir/dist dist
COPY failed: stat /var/lib/docker/tmp/docker-builder326636018/workdir/dist: no such file or directory

最佳答案

COPY ./workdir 更改为 COPY workdir

https://github.com/docker/for-linux/issues/90#issuecomment-326045261

Paths in a Dockerfile are always relative to the the context directory. The context directory is the positional argument passed to docker build (often .).

If there is no ./tmp in the context directory then this is the expected behaviour.

关于Docker 无法使用复制命令找到文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50918103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com