Wine无法在Google Cloud Run上运行(Google Cloud Run的限制)

时间:2020-07-06 23:54:28

标签: docker google-cloud-run wine

这是我的docker文件,正在安装wine,以便在Google云上运行一些我想运行的exe:

ARG BASE_IMAGE="ubuntu"
ARG TAG="latest"
FROM ${BASE_IMAGE}:${TAG}

# Install prerequisites
RUN apt-get update \
    && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
        apt-transport-https \
        ca-certificates \
        cabextract \
        git \
        gosu \
        gpg-agent \
        p7zip \
        pulseaudio-utils \
        software-properties-common \
        tzdata \
        unzip \
        wget \
        winbind \
        xvfb \
        zenity \
    && rm -rf /var/lib/apt/lists/*

# Install wine
ARG WINE_BRANCH="stable"
RUN wget -O- -nv https://dl.winehq.org/wine-builds/winehq.key | apt-key add - \
    && apt-add-repository "deb https://dl.winehq.org/wine-builds/ubuntu/ $(grep VERSION_CODENAME= /etc/os-release | cut -d= -f2) main" \
    && dpkg --add-architecture i386 \
    && apt-get update \
    && DEBIAN_FRONTEND="noninteractive" apt-get install -y --install-recommends winehq-${WINE_BRANCH} \
    && rm -rf /var/lib/apt/lists/*

# Install winetricks
RUN wget -nv https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks -O /usr/bin/winetricks \
    && chmod +x /usr/bin/winetricks

# Download gecko and mono installers
COPY download_gecko_and_mono.sh /root/download_gecko_and_mono.sh
RUN chmod +x /root/download_gecko_and_mono.sh \
    && /root/download_gecko_and_mono.sh "$(dpkg -s wine-${WINE_BRANCH} | grep "^Version:\s" | awk '{print $2}' | sed -E 's/~.*$//')"

RUN apt-get update
RUN apt-get install -y python3.6 python3-pip
RUN pip3 install flask gunicorn
RUN apt-get install -y nginx
COPY . /app

WORKDIR /app
RUN chmod a+x /usr/bin/wine
ENTRYPOINT ["/usr/local/bin/gunicorn","-w","1","--timeout","900","-b","0.0.0.0:8005","app:app"]
EXPOSE 8005

我已经在我的linux 64位计算机上本地测试了此容器,并且它能够运行wine命令(app.py是调用exes的flask服务器)。 但是,当我尝试在GCR容器上调用“葡萄酒”时(我什至尝试在app.py的开头调用它(可以保证运行)),都会出现此错误:

Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/base.py", line 119, in init_process self.load_wsgi() File "/usr/local/lib/python3.8/dist-packages/gunicorn/workers/base.py", line 144, in load_wsgi self.wsgi = self.app.wsgi() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/wsgiapp.py", line 49, in load return self.load_wsgiapp() File "/usr/local/lib/python3.8/dist-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp return util.import_app(self.app_uri) File "/usr/local/lib/python3.8/dist-packages/gunicorn/util.py", line 358, in import_app mod = importlib.import_module(module) File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/app/app.py", line 27, in <module> print(subprocess.call(["wine"]) File "/usr/lib/python3.8/subprocess.py", line 340, in call with Popen(*popenargs, **kwargs) as p: File "/usr/lib/python3.8/subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) OSError: [Errno 8] Exec format error: 'wine'

错误的重要所在是:

OSError: [Errno 8] Exec format error: 

这特别奇怪,因为我认为docker将保证在Linux平台之间的可移植性。

编辑:

最初的问题是我没有使用wine64(gcr仅支持linux 64位二进制文​​件),从而解决了wine运行的最初问题。

但是,由于使用gVisor沙箱完全管理了Cloud Run,因此仍然无法运行我的exe。 我最终转向其他方法来解决我的问题。

1 个答案:

答案 0 :(得分:1)

很可能Wine无法在完全托管的Cloud Run上运行。

完全托管的Cloud Run使用gVisor沙箱(https://gvisor.dev/),它是用Go语言编写的用户空间系统调用模拟器。此环境无法运行真正的Linux内核或真正的Docker运行时。

期望与Wine等奇特的可执行文件可能存在兼容性问题(Wine会在最大范围和极端情况下使用syscall API)。但是,大多数服务器端应用程序都可以正常运行。

您可以use strace on Cloud Run来识别罪魁祸首syscall,并make a feature request to gVisor提到您需要在Cloud Run上使用它。另外,您可以将Cloud Run for Anthos与Kubernetes一起运行,并使用真正的Linux内核和Docker(或容器)。