2

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?

Genos
  • 413
  • 4
  • 12

4 Answers4

2

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

apk add upx
Genos
  • 413
  • 4
  • 12
0

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.

Neekoy
  • 2,325
  • 5
  • 29
  • 48
  • The content of an Upx tar is a folder named upx-$VERSION-amd64_linux. Inside there is a bunch of files, including upx itself. So I don't think this is correct. Anyway I've tried it and now running upx returns 'line 1: ooooo: not found' – Genos Aug 14 '18 at 14:06
0

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

franchb
  • 1,174
  • 4
  • 19
  • 42
0

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