0

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
Hammed
  • 1,457
  • 1
  • 24
  • 37
  • 1
    Include your Dockerfile, a write-up like this doesn't help anyone. – Quinten Scheppermans Dec 12 '19 at 09:08
  • I've added the Dockerfile and dockerignore file – Hammed Dec 12 '19 at 10:28
  • Seems like dr Steins answer is correct, it can only find files from the directory itself and its subdirectories. I've removed my answer. If you build the docker image from your root directory then it will be able to find /Function. See this post: https://stackoverflow.com/questions/24537340/docker-adding-a-file-from-a-parent-directory – Quinten Scheppermans Dec 12 '19 at 10:29

1 Answers1

3

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 . 
Dr.Stein
  • 121
  • 1
  • 4