简体   繁体   English

无法在 docker linux 容器中启动 chrome

[英]Cant launch chrome in docker linux container

I have an asp.net core application that uses the jsreport nuget packages to run reports.我有一个 asp.net 核心应用程序,它使用 jsreport nuget 包来运行报告。 I am attempting to deploy it with a linux docker container.我正在尝试使用 linux docker 容器部署它。 I seem to be having trouble getting chrome to launch when I run a report.我在运行报告时似乎无法启动 chrome。 I am getting the error:我收到错误:

Failed to launch chrome!  Running as root without --no-sandbox is not supported.

I have followed the directions on the .net local reporting page ( https://jsreport.net/learn/dotnet-local ) regarding docker, but I am still getting the error.我已按照 .net 本地报告页面 ( https://jsreport.net/learn/dotnet-local ) 上关于 docker 的说明进行操作,但我仍然收到错误消息。

Here is my full docker file:这是我的完整 docker 文件:

#use the .net core 2.1 runtime default image
FROM microsoft/dotnet:2.1-aspnetcore-runtime

#set the working directory to the server
WORKDIR /server

#copy all contents in the current directory to the container server directory
COPY . /server

#install node
RUN apt-get update -yq \
    && apt-get install curl gnupg -yq \
    && curl -sL https://deb.nodesource.com/setup_8.x | bash \
    && apt-get install nodejs -yq

#install jsreport-cli
RUN npm install jsreport-cli -g

#install chrome for jsreport linux
RUN apt-get update && \   
    apt-get install -y gnupg  libgconf-2-4 wget && \
    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
    sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
    apt-get update && \
    apt-get install -y google-chrome-unstable --no-install-recommends

ENV chrome:launchOptions:executablePath google-chrome-unstable
ENV chrome:launchOptions:args --no-sandbox

#expose port 80
EXPOSE 80

CMD dotnet Server.dll

Is there another step that I am missing somewhere?有没有我在某处遗漏的另一个步骤?

Its little late but may be can help someone else.它有点晚了,但可能可以帮助别人。

For me, the only option that was needed to fix this issue in the docker container was to run chrome in a headless mode (so cause was in tests not in dockerfile).对我来说,在 docker 容器中解决这个问题所需的唯一选项是在无头模式下运行 chrome(所以原因是在测试中而不是在 dockerfile 中)。

ChromeOptions options = new ChromeOptions().setHeadless(true); 
WebDriver driver = new ChromeDriver(options);

Results: Now tests run successfully, without any errors.结果:现在测试成功运行,没有任何错误。

扩展 Pramod 的答案,我自己的问题只能通过同时运行--headless--no-sandbox标志来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM