【问题标题】:Chrome/Chromium inside Docker and the sandboxDocker 和沙箱中的 Chrome/Chromium
【发布时间】:2018-08-30 12:37:09
【问题描述】:

我想运行一个容器化的 Chromium,但我遇到了沙盒问题。我正在运行 Chromium “原始构建”(不是通过包管理器下载的,但这不应该有什么不同,fwiw)。这是一个最小的 Dockerfile,可以说明我的问题:

FROM ubuntu:16.04

RUN set -ex; \
    apt-get update; \
    apt-get install curl unzip gconf-service libasound2 libatk1.0-0 libatk-bridge2.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 -y;

RUN set -ex; \
# download and install Chromium build, set permissions
    curl -o /tmp/chromium-download.zip https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/561732/chrome-linux.zip; \
    unzip -d /opt /tmp/chromium-download.zip; \
    chmod -R go=u-w /opt/chrome-linux; \
# create 'chrome' group and user
    groupadd --system chrome; \
    useradd --system --create-home --gid chrome --groups audio,video chrome; \
# Advice re. SUID sandbox in 'Installation instructions for “Raw builds of Chromium”':
# https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md#installation-instructions-for-raw-builds-of-chromium
    chown root:root /opt/chrome-linux/chrome_sandbox; \
    chmod 4755 /opt/chrome-linux/chrome_sandbox;

ENV CHROME_DEVEL_SANDBOX="/opt/chrome-linux/chrome_sandbox"
USER chrome
ENV PATH="${PATH}:/opt/chrome-linux"

构建它并尝试运行它:

$ docker build . -t chromium
$ docker run -it chromium:latest chrome --headless

我收到以下错误:

[0830/122656.151751:FATAL:zygote_host_impl_linux.cc(127)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.

最常见的故障排除口头禅(例如 here;不同的项目,但相同的问题):“只需添加 --no-sandbox 就可以了”。这确实有效。

但是,官方消息来源不建议这样做,并声称“如果您在容器中正确设置用户,则不需要这样做”。 (见here)。根据我的感觉,容器内的用户创建正确,并且我还按照建议设置了 SUID 沙箱的权限(我不清楚其实际角色,this 页面说“Linux SUID 沙箱几乎但没有完全删除。”——不管这在实践中意味着什么)。

是否有机会在不禁用沙盒的情况下运行它? (因为这是用于测试的,我希望保留沙盒行为,因为我想尽可能地模拟“自然”环境)

【问题讨论】:

    标签: google-chrome docker dockerfile chromium


    【解决方案1】:

    在内核中启用用户命名空间。 >>another relevant thread

    【讨论】:

    • 谢谢。我也来到了这个解决方案,这可能是最好的方法。但是我没有找到任何方法(轻松)在我们的 CI 环境中设置它。所以最后我不得不选择--no-sandbox
    猜你喜欢
    • 1970-01-01
    • 2018-09-04
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    相关资源
    最近更新 更多