无法使用 Alpine 和 Busybox docker 镜像运行可执行文件

我正在尝试创建一个非常简单的 docker 镜像,它必须预先安装 lua、luarocks 和另外一些可执行文件,Dockerfile 如下:

FROM busybox AS builder

WORKDIR /usr/local/bin

# 安装 curl(可靠的 wget 替代品)
RUN wget -O curl https://github.com/moparisthebest/static-curl/releases/download/v7.79.1/curl-amd64 && \
    chmod +x curl

# 安装 luaformatter
RUN wget -O lua-format https://github.com/Koihik/vscode-lua-format/raw/master/bin/linux/lua-format && \
        chmod +x lua-format

# 安装 stylua
RUN wget -O stylua-0.11.0-linux.zip https://github.com/JohnnyMorganz/StyLua/releases/download/v0.11.0/stylua-0.11.0-linux.zip && \
        unzip stylua-0.11.0-linux.zip && \
        rm stylua-0.11.0-linux.zip && \
        chmod +x stylua

# 安装 selene
RUN wget -O selene-light-0.14.0-linux.zip https://github.com/Kampfkarren/selene/releases/download/0.14.0/selene-light-0.14.0-linux.zip && \
        unzip selene-light-0.14.0-linux.zip && \
        rm selene-light-0.14.0-linux.zip && \
        chmod +x selene

# 安装 lua(独立二进制文件)
RUN curl -k -o lua-5.4.2_Linux54_64_bin.tar.gz -L https://sourceforge.net/projects/luabinaries/files/5.4.2/Tools%20Executables/lua-5.4.2_Linux54_64_bin.tar.gz && \
    tar xvf lua-5.4.2_Linux54_64_bin.tar.gz && \
    mv lua54 lua && \
    rm -rf lua-5.4.2_Linux54_64_bin.tar.gz luac54

# 安装 luarocks(独立二进制文件)
RUN wget -O luarocks-3.7.0-linux-x86_64.zip https://luarocks.github.io/luarocks/releases/luarocks-3.7.0-linux-x86_64.zip && \
    unzip luarocks-3.7.0-linux-x86_64.zip && \
    mv luarocks-3.7.0-linux-x86_64/luarocks . && \
    rm -rf luarocks-3.7.0-linux-x86_64*

FROM busybox

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

WORKDIR /ataraxis

RUN luarocks install luacheck

CMD stylua lua/ataraxis && \
    lua-format -i lua/ataraxis/*.lua && \
    luacheck --config .luacheckrc lua/ataraxis/*.lua && \
    selene lua/ataraxis

我尝试使用 Alpine 和 Busybox 作为我的 Dockerfile 的基础映像,但是运行这些可执行文件时没有成功,即使它们位于 $PATH 中默认包含的目录中(/usr/local/bin),每当我尝试运行其中任何一个时,都会显示以下错误:

$ lua
/bin/sh: lua: not found

我已经搜索并尝试了我能想到的每一个可能的解决方案,但仍然没有运气。

原文链接 https://stackoverflow.com/questions/69607005

点赞
stackoverflow用户7509065
stackoverflow用户7509065

valiano's 答案很好地解释了问题。然而,还有另一种解决方案他没提到,它不需要你使用 glibc: 如果你从源代码构建那些程序(无论是在容器中作为构建过程的一部分,还是在任何其他基于 musl 的环境中),而不仅仅是下载二进制文件,那么它们将在你的容器中正常工作。

2021-10-18 02:10:06