Docker build ADD vs RUN curl
ADD
is executed in docker host.
The
ADD
instruction copies new files, directories or remote file URLs from<src>
and adds them to the filesystem of the image at the path<dest>
.
RUN
is executed inside your container.
The
RUN
instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in theDockerfile
.
Specifically the command RUN curl -o file.txt http://X.X.X.X/path/to/file/file.txt
executes curl that must have already been installed in the image we are using. If the curl command has not been installed (and is not present in the base image) the entire RUN
command fails.Instead the command ADD
url can be performed even without having installed curl
(or analogues) inside the container just because it is executed by the host (it uses the Go libraries with which it is written docker) during the creation of our image.
Is http://X.X.X.X/path/to/file/file.txt
accessible outside of your docker container?
Edit: as confirmed by the author of the question:
My docker host lives behind a firewall that has a proxy set in the
/etc/default/docker
file. So while I wanted to grab a file internal to the network I'm on, the proxy caused it to look outside the network.