Copy Files from External URLs Into a Container With Dockerfile

This post will show how to copy files from an external URL directly into a Docker container using a Dockerfile.

Building Docker images with a Dockerfile is the most common method to build and reuse images. When building images, sometimes there is a need to download files from the external website (URL) directory into the container.

ADD

With the Docker ADD statement, we can download files directly into the container from an external site and essentially copy them.

Note: ADD and COPY statements are not the same. Read more in this post.

In the following Dockerfile, we use the ADD statement to download PowerShell 7 latest build directly into the container.

Dockerfile

FROM ubuntu
RUN apt-get update
RUN mkdir downloads
ADD https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/powershell_7.1.4-1.ubuntu.20.04_amd64.deb /downloads


Posted

in

,

by