Chrome 加载共享库失败:libX11.so.6

Chrome fails to load shared libraries: libX11.so.6

我们有一个 Docker 文件直到 2020 年 12 月 22 日才运行,但如果我们再次构建相同的 Docker 文件,它会突然在运行时崩溃,异常是:

PuppeteerSharp.ProcessException: Failed to launch Base! /app/.local-chromium/Linux-706915/chrome-linux/chrome: error while loading shared libraries: libX11.so.6: cannot open shared object file: No such file or directory

这是 docker 文件的相关部分:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

#Excluded since it is not relevant

#####################
#PUPPETEER RECIPE
#####################
RUN apt-get update && apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    --no-install-recommends \
    && curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
    && apt-get update && apt-get install -y \
    google-chrome-beta \
    fontconfig \
    fonts-ipafont-gothic \
    fonts-wqy-zenhei \
    fonts-thai-tlwg \
    fonts-kacst \
    fonts-symbola \
    fonts-noto \
    fonts-freefont-ttf \
    --no-install-recommends \
    && apt-get purge --auto-remove -y curl gnupg \
    && rm -rf /var/lib/apt/lists/*

#####################
#END PUPPETEER RECIPE
#####################

ENV PUPPETEER_EXECUTABLE_PATH "/usr/bin/google-chrome-beta"

WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Our.File.dll"]

我绝对不是经验丰富的 Docker/Linux 开发人员,但我们的产品已经运行了将近一年。

在搜索问题时,我们发现了很多可以尝试的方法。我尝试过但都失败了的事情包括:

  1. 手动添加依赖项(在上面的 运行 apt-get 之前和之后尝试过):
RUN apt-get update && apt-get install -y \
          gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
          libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
          libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
          libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
          ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

此建议最初是在此处找到的:https://medium.com/@ssmak/how-to-fix-puppetteer-error-while-loading-shared-libraries-libx11-xcb-so-1-c1918b75acc3 在查看构建输出时,我们注意到大多数依赖项已经存在于最新版本中。

  1. 试图指定旧版本的 Chrome(我们尝试了几个不同的版本):
#####################
#PUPPETEER RECIPE
#####################
ARG CHROME_VERSION="81.0.4044.138-1"
RUN apt-get update && apt-get -f install && apt-get -y install wget gnupg2 apt-utils
RUN wget --no-verbose -O /tmp/chrome.deb http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb \
&& apt-get update \
&& apt-get install -y /tmp/chrome.deb --no-install-recommends --allow-downgrades fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \
&& rm /tmp/chrome.deb

#####################
#END PUPPETEER RECIPE
#####################
  1. 一起尝试了 3 加 2
  2. 还尝试将 libgbm-dev 添加到依赖项列表中,因为我们在某处找到了它。

我已尝试通过 运行 容器中的这些命令(及其输出)来验证文件是否存在于 docker 文件中:

root@5c47052da1d8:/app# dpkg-query -L libx11-6
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0
/usr/share
/usr/share/doc
/usr/share/doc/libx11-6
/usr/share/doc/libx11-6/NEWS.Debian.gz
/usr/share/doc/libx11-6/NEWS.gz
/usr/share/doc/libx11-6/changelog.Debian.gz
/usr/share/doc/libx11-6/changelog.gz
/usr/share/doc/libx11-6/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/libx11-6
/usr/lib/x86_64-linux-gnu/libX11.so.6
root@5c47052da1d8:/app# ls -la /usr/lib/x86_64-linux-gnu/libX11.so.6
lrwxrwxrwx 1 root root 15 Sep 11 16:16 /usr/lib/x86_64-linux-gnu/libX11.so.6 -> libX11.so.6.3.0
root@5c47052da1d8:/app# ldd libX11.so.6
ldd: ./libX11.so.6: No such file or directory
root@5c47052da1d8:/app# ldd /usr/lib/x86_64-linux-gnu/libX11.so.6
        linux-vdso.so.1 (0x00007ffc432b3000)
        libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fe8b0ad2000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe8b0acd000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe8b090c000)
        libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fe8b0708000)
        libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fe8b0502000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fe8b0c45000)
        libbsd.so.0 => /usr/lib/x86_64-linux-gnu/libbsd.so.0 (0x00007fe8b04e8000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe8b04dc000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe8b04bb000)

我已阅读https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

任何帮助将不胜感激,因为我不知道如何解决这个问题或接下来要尝试什么。

因此,我发现了问题并在其他人身上发生时记录在此处。原来是Visual Studio现在做的建筑。

如果我右键单击并在 Visual Studio 中构建 Dockerfile,结果将是正确的,正如我上面的调查所显示的那样。问题是,当我想测试图像时,我在 VS 中按 F5(或 Ctrl+F5)运行 它,在这种情况下 Visual Studio 默认情况下不会构建我的 Dockerfile。我以为它使用了我最近的构建结果(缓存),但实际上它使用了另一个缓存结果。出于性能原因,它在本地构建项目并获取结果并将其添加到 aspnet:3.1-buster-slim 图像,这意味着我的自定义依赖项未添加。

可以通过项目文件中的设置来控制此行为。 if 的默认值是 Fast,它不使用我的 Dockerfile,但将其设置为 Regular 会以较慢的启动成本为代价。 可以在此处找到此设置和其他设置的文档:https://docs.microsoft.com/en-us/visualstudio/containers/container-msbuild-properties?view=vs-2019