Alpine Docker container doesn't recognize UPX as an executable

2.1k Views Asked by At

Stackers,

I'm using Docker to containerize my app. In the stage below, I'm trying to pack it using UPX.

FROM alpine:3.8 AS compressor

# Version of upx to be used(without the 'v' prefix)
# For all releases, see https://github.com/upx/upx/releases
ARG UPX_VERSION=3.94

# Fetch upx, decompress it, make it executable.
ADD https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz /tmp/upx.tar.xy
RUN tar -xJOf /tmp/upx.tar.xy upx-${UPX_VERSION}-amd64_linux/upx > /usr/local/bin/upx \ 
 && chmod +x /usr/local/bin/upx

COPY --from=builder /usr/local/bin/ace /usr/local/bin/ace

RUN /usr/local/bin/upx --overlay=strip --best /usr/local/bin/ace

The thing is when I build the image I get the following error:

The command '/bin/sh -c /usr/local/bin/upx --overlay=strip --best /usr/local/bin/ace' returned a non-zero code: 127

For some reason, the container doesn't recognize upx as executable! Can anyone give me some pointers?

4

There are 4 best solutions below

0
On BEST ANSWER

Turns out there is an apk package for UPX. The easier way to install is:

apk add upx
0
On

To get it working with Dockerfile:

(adjust Alpine version to your liking)

FROM alpine:latest as build
RUN apk add --no-cache upx

# Build and use upx as applicable...
1
On

The archive you have is just the file, so you can't address it by name. If you extract the whole thing (which is just the file) it works. Change the corresponding line in your Dockerfile to the following:

RUN tar -xJOf /tmp/upx.tar.xy upx-${UPX_VERSION}-amd64_linux > /usr/local/bin/upx \

Note that I removed the filename from the archive name.

0
On

Add apk add --no-cache upx=3.95-r1 as for March 2019.