1

I'm in the process of writing container features and I want to be able to install package on debian:latest, ubuntu:latest and alpine:latest. To do so, I'm willing to leverage pacapt, a pure shell cross-os solution.

First, I need to be able to download the script itself and that's where is become tricky. The base images have little to offer (no curl, wget or telnet), see available package on bare images:

Constraints

Shell

I'm looking for a POSIX solution.

Available command

Here is what is missing (prefixed by -) and what is present (prefixed by +) on all of them.

-curl
-wget
-openssl
-telnet
-git
-nc
-netcat
+awk

HTTPS

The file I aim to download is pacapt script hosted on GitHub, located at

https://raw.githubusercontent.com/icy/pacapt/ng/pacapt

Questions

How to download file from docker container image without curl / wget?

Related:

1 Answers1

1

You can set up a multi-stage build and download the file into a throwaway image first, then copy it into the target image. An example is shown in the documentation for multi-stage builds. All of this should be put in a single Dockerfile:

FROM golang:1.16 AS builder
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v golang.org/x/net/html  
COPY app.go ./
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o app .

FROM alpine:latest
RUN apk --no-cache add ca-certificates WORKDIR /root/ COPY --from=builder /go/src/github.com/alexellis/href-counter/app ./ CMD ["./app"]

The general syntax is:

COPY --from=stage_or_image source_path_in_the_image target_path

It works like regular COPY, except the source is the image specified, rather than the build directory on the host. You can specify independent images too:

COPY --from=nginx:latest /etc/nginx/nginx.conf /nginx.conf

For your use case you would either find an image with the file you need and copy from it, or alternatively first use a container with curl/wget to download the file, then copy it.

gronostaj
  • 58,482