Bailey Miller
Bailey Miller

Reputation: 1523

Docker cannot find file or directory with copy command

So I am pretty new to docker and it's setup but I have been messing around with this dockerfile for about half an hour trying to get a working image together for an angular 6 application that I have.

Aside from the messy dockerfile the last bit doesn't seem to be working. So I am working inside of the /workdir directory for all this stuff, building my angular app, etc. Afterwards I move out to the root directory and then want to copy the /workdir/dist directory to the root /dist folder and then delete the working directory. I get a file or directory not found at the copy line. However if I run ls I see a workdir exists and if I run ls ./workdir/dist I see that there are files in it.

My linux scripting and docker understanding is very limited but I cannot see why this seems to fail.

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}

My last few lines from the docker build command:

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

Upvotes: 3

Views: 9556

Answers (1)

wgl
wgl

Reputation: 39

Change COPY ./workdir to 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.

Upvotes: 1

Related Questions