0

I keep my image on a fork repo of the official docker ubuntu images, the Dockerfile I am working on is in another repo I am trying to mention the relative path to the image like this:

FROM scratch
ADD ./../../../Dev-Ops-docker-brew-ubuntu-core/bionic/ubuntu-bionic-core-cloudimg-amd64-root.tar.gz /

but it doesn´t work, I get

=> ERROR [1/4] ADD ./../../../Dev-Ops-docker-brew-ubuntu-core/bionic/ubuntu-bionic-core-cloudimg-amd64-root.tar.  0.0s
------
 > [1/4] ADD ./../../../Dev-Ops-docker-brew-ubuntu-core/bionic/ubuntu-bionic-core-cloudimg-amd64-root.tar.gz /:
------
failed to compute cache key: "/Dev-Ops-docker-brew-ubuntu-core/bionic/ubuntu-bionic-core-cloudimg-amd64-root.tar.gz" not found: not found
P

Is there a way to specify the path of the image or to reference the image I don´t want it to add it also in this git repo?

Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179
  • This is a kind of dupe of https://stackoverflow.com/questions/39376786/docker-and-symlinks. Basically you can't add from outside of the build context like that, you either need to expand the build context or use one of those work arounds if building with docker. – Matt May 19 '21 at 05:08
  • Normally you would build and push your other project to a common registry and go `FROM` there. – Matt May 19 '21 at 05:08
  • @Matt I tried and work to run the docker file on the parent folder of the two repos and I will be needing more repos so I think the approach in the answer I posted is the right one. – Eduard Florinescu May 19 '21 at 05:10
  • 1
    Yeah that works. The main issue you can run into then is build context size... everything in the context is sent as a tar to the docker daemon so you can get slow build starts if there's some large data. `.dockerignore` can help with this though. – Matt May 19 '21 at 05:15
  • @Matt can I add that caveat to the answer? – Eduard Florinescu May 19 '21 at 05:17
  • yeah of course.. – Matt May 19 '21 at 05:24

1 Answers1

1

Researching more it seems for security reasons you are not allowed to go upper to parent in folders, so the best way is too run the build on the folder that is common parent for the two repos like this, and specify the Dockerfile in the subfolder (Powershell in my case notice the backslashes):

docker image build --tag "eduardflorinescu/test" --file ".\DevOps-Tools\docker\frontend\Dockerfile" .

and in this case the ADD section will be:

FROM scratch
ADD Dev-Ops-docker-brew-ubuntu-core/bionic/ubuntu-bionic-core-cloudimg-amd64-root.tar.gz /

This approach has the advantage if there are more repos you need to add files from to the image.

One probable caveat mentioned in comments by Matt :

the main issue you can run into then is build context size... everything in the context is sent as a tar to the docker daemon so you can get slow build starts if there's some large data. .dockerignore can help with this though

Eduard Florinescu
  • 16,747
  • 28
  • 113
  • 179