簡體   English   中英

無法在 docker linux 容器中啟動 chrome

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM