Open bchallenor opened 6 years ago
ADD
like COPY
is to copy external resources, not for in-Docker file transfer. You may want to expose your web
container.
These are external resources - it's a package manager proxy that is running in the other container. It behaves the same as a public URL, but with better performance.
As I said, you can achieve the same (apart from the desirable cache invalidation behaviour) with RUN curl
. It seems inconsistent that ADD <URL>
doesn't also use the supplied network.
I see your point. It is that makes more sense to external resources be exposed.
But I agree with you that RUN
and ADD
are in dissonance.
cc @dnephin @tonistiigi @thaJeztah
ADD
is not executed inside a container; it's the daemon that fetches the resources (either local files, or from remote). The daemon's networking is not part of the container-container network, thus cannot contact the container if that container doesn't publish its ports.
Configurations like these was part of the reason for the long delay before --network
was added to docker build
(docker build
is dependent on other containers, and networks, to be created before the build can be performed).
It behaves the same as a public URL, but with better performance.
Does it work for you if you publish that container on localhost?
Yes, it does work if the proxy container and the build are both run on the host network, with the port exposed but bound only to localhost. Sometimes it's nice to be able to run the package manager command inside the built image though (to test if the image needs rebuilding, if any deps have changed), but that means that the image also must be run on the host network, which is a bit restricting.
A different feature request that occurred to me but might be more generally useful to other people would be adding a flag to RUN
to give it similar cache-busting functionality to ADD
- something that meant "always run this command, but if it produces an identical layer to the last build, then continue to use the previous build's cached layers". Example:
RUN expensive-command
RUN --try-cache curl --remote-name http://web-container/info
RUN another-expensive-command
Then RUN --try-cache curl
(flag name up for debate!) behaves like ADD
, i.e. another-expensive-command
is run if and only if the contents of http://web-container/info
changed.
RUN --try-cache apt-get update
would, I think, be widely useful to other people, and would align with the general deprecation of ADD
.
Per-command cache control is added in https://github.com/moby/buildkit/ . There is no dockerfile syntax to set it yet though but discussed in https://github.com/moby/buildkit/issues/242 .
I think ADD
should be deprecated and removed.
@dnephin Not removed, but replaced with FROM https://foo.tgz
, COPY --from=https://foo.tgz
, FROM git://github.com/foo/bar.git#master
When building, the
--network
flag affectsRUN
statements but notADD
statements. I would like it to supportADD
too. This would not make builds any less reproducible, because of course you can already useRUN curl
, butADD
would give better control of cache invalidation.Test case: