我正在尝试在 docker 容器内运行一组带有无头镀铬的仪表规格。
我试过像这样设置一个 Dockerfile:
FROM maven:latest
RUN apt-get update && apt-get install -q -y unzip curl
ENV DEBIAN_FRONTEND=noninteractive
# requirements for chrome headless
# https://github.com/Googlechrome/puppeteer/issues/290#issuecomment-322838700
RUN apt-get update && apt-get install -y gnupg &&\
curl -sL https://deb.nodesource.com/setup_11.x | bash - &&\
apt-get update && apt-get install -y nodejs make g++ &&\
apt-get update &&\
apt-get install -y git-all 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 &&\
apt autoremove -y &&\
rm -rf /var/lib/apt/lists/*
# Install Google Chrome
RUN curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
apt-get -yqq update && \
apt-get -yqq install google-chrome-stable && \
rm -rf /var/lib/apt/lists/*
# Install gauge
RUN apt-get install unzip
RUN curl -L https://github.com/getgauge/gauge/releases/download/v1.0.5/gauge-1.0.5-linux.x86_64.zip -o /gauge-1.0.5-linux.x86_64.zip
RUN unzip -o gauge-1.0.5-linux.x86_64.zip -d /usr/local/bin
# Install gauge plugins
RUN gauge install java && \
gauge install screenshot
ENTRYPOINT ["mvn"]
注意:这里有少量专有的东西我不得不删除,但它不应该有所作为。
还要注意我工作的 CI 系统会处理很多事情,例如将卷安装到容器中,从 git 获取存储库,分配端口等。
当 CI 系统使用此容器运行量规规范时,它们都会失败并出现如下错误:
INFO: Created user preferences directory.
17:55:37 Starting ChromeDriver 75.0.3770.8 (681f24ea911fe754973dda2fdc6d2a2e159dd300-refs/branch-heads/3770@{#40}) on port 26120
17:55:37 Only local connections are allowed.
17:55:37 Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
17:55:37 [1560441336.946][SEVERE]: bind() failed: Cannot assign requested address (99)
17:55:37 Failed to take regular screenshot:
17:55:37 No X11 DISPLAY variable was set, but this program performed an operation which requires it.
17:55:37 Failed to take regular screenshot:
17:55:37 No X11 DISPLAY variable was set, but this program performed an operation which requires it.
17:55:37 Error Message: org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
17:55:37 (unknown error: DevToolsActivePort file doesn't exist)
17:55:37 (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
17:55:37 Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
17:55:37 System info: host: 'dae4cd1c9fcd', ip: '10.99.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-1029-gcp', java.version: '11.0.1'
17:55:37 Driver info: driver.version: GaugeDriver
17:55:37 remote stacktrace: #0 0x562fab6bd299 <unknown>
所以看起来无头 chrome 实例甚至没有启动。但是,我无法弄清楚为什么。