Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker build ADD vs RUN curl

If I run a dockerfile where I have a command like

RUN curl -o file.txt http://X.X.X.X/path/to/file/file.txt

the build works, whereas if I use

ADD http://X.X.X.X/path/to/file/file.txt file.txt

The build fails and it complains about

Got HTTP status code >= 400: 503 Service Unavailable

Is there something about ADD that I'm not understanding?

Edit the file is also accessible through the docker host.

like image 630
Erik Nguyen Avatar asked Jul 01 '15 21:07

Erik Nguyen


People also ask

What is the difference between docker build and run?

docker build builds a new image from the source code. docker create creates a writeable container from the image and prepares it for running. docker run creates the container (same as docker create ) and runs it.

What is the difference between docker add and docker COPY?

COPY is a docker file command that copies files from a local source location to a destination in the Docker container. ADD command is used to copy files/directories into a Docker image. It only has only one assigned function. It can also copy files from a URL.

What is the advantage of add command in comparison to COPY in docker?

COPY takes in a src and destination. It only lets you copy in a local file or directory from your host (the machine building the Docker image) into the Docker image itself. ADD lets you do that too, but it also supports 2 other sources. First, you can use a URL instead of a local file / directory.

What is add in Dockerfile?

The ADD command is used to copy files/directories into a Docker image. It can copy data in three ways: Copy files from the local storage to a destination in the Docker image. Copy a tarball from the local storage and extract it automatically inside a destination in the Docker image.


1 Answers

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 the Dockerfile.

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.

like image 55
fox91 Avatar answered Sep 18 '22 23:09

fox91