Download files from URLs

Context #

When creating a Dockerfile, it is common to download artifacts, tar files, etc. from external URLs. Usually, developers will use a RUN instruction that invokes curl or wget to accomplish this. The dockerfile specification provides a baked-in alternative, the ADD instruction.

How to use #

Besides copying files and directories from the build context, the ADD statement can download files from an external URL, as shown in the example below:

FROM ubuntu:latest

ADD https://github.com/roboll/helmfile/releases/download/v0.138.7/helmfile_linux_amd64 /usr/local/bin/helmfile

RUN chmod +x /usr/local/bin/helmfile

ENTRYPOINT ["/usr/local/bin/helmfile"]

Notes #

  • The downloaded file will have 0600 as permission, which in case of a binary means that you will have to run a subsequent RUN command to update the executable bit (as shown in the example above).
  • If the URL is protected with authentication, you need to use wget or curl instead, since the ADD instruction doesn't support authentication

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.