Hammed
Hammed

Reputation: 1557

Docker build "no such file or directory" error


RUN adduser -D appUser

RUN mkdir /usr/share/app

RUN mkdir /logs

ADD Function/target/foo.jar /usr/share/app

WORKDIR /usr/share/app

RUN chown -R  appUser /usr/share/app

RUN chown -R  appUser /logs

USER appUser

EXPOSE 8080

ENTRYPOINT ["java", "-jar",  "foo.jar"]`

I've got this weird issue I can't seem to work my head around.

My root folder contains two directories, (both with subdirectories) 'Demo/Dockerfile' and 'Function/target/foo.jar'

I have a copy command in my Dockerfile that reads

COPY Function/target/foo.bar /usr/share/app

but when I run docker build -f Demo/Dockerfile from the root folder, I get an error

stat /var/lib/docker/tmp/docker-builder238823934/Function/target/foo.jar: no such file or directory

I find this a bit strange because when I edit the copy command to read COPY /target/foo.bar /usr/share/app and then I cd into the Function directory and run docker build -f ../Demo/Dockerfile

it builds successfully, or if I edit the Dockerfile to read COPY foo.bar /usr/share/app and then cd into the target directory and run docker build -f ../../Demo/Dockerfile, this also works.

Is there an explanation for this sort of behavior?

This is what my dockerignore file looks like



!**/Dockerfile


!DockerServiceDescription/**


!Function/target/*.war


!server.xml


!tomcat-users.xml

Upvotes: 0

Views: 2668

Answers (1)

Dr.Stein
Dr.Stein

Reputation: 121

Docker uses context directory and children only and does not allow using any files outside for security reasons.

You should show context directory to docker using '.' or so:

cd myproject
docker build -f Demo/Dockerfile . 

Upvotes: 3

Related Questions