[英]Cant launch chrome in docker linux container
我有一个 asp.net 核心应用程序,它使用 jsreport nuget 包来运行报告。 我正在尝试使用 linux docker 容器部署它。 我在运行报告时似乎无法启动 chrome。 我收到错误:
Failed to launch chrome! Running as root without --no-sandbox is not supported.
我已按照 .net 本地报告页面 ( https://jsreport.net/learn/dotnet-local ) 上关于 docker 的说明进行操作,但我仍然收到错误消息。
这是我的完整 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
有没有我在某处遗漏的另一个步骤?
它有点晚了,但可能可以帮助别人。
对我来说,在 docker 容器中解决这个问题所需的唯一选项是在无头模式下运行 chrome(所以原因是在测试中而不是在 dockerfile 中)。
ChromeOptions options = new ChromeOptions().setHeadless(true);
WebDriver driver = new ChromeDriver(options);
结果:现在测试成功运行,没有任何错误。
扩展 Pramod 的答案,我自己的问题只能通过同时运行--headless
和--no-sandbox
标志来解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.