所以我对docker来说还很陌生,它已经设置好了,但是我一直在弄混这个dockerfile大约半小时,试图为我拥有的angular 6应用程序收集工作图像。

除了凌乱的dockerfile之外,最后一点似乎不起作用。
因此,我正在/workdir目录中进行所有工作,构建我的 Angular 应用程序等。之后,我移至根目录,然后将/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

10-07 17:05