简体   繁体   中英

Cant launch chrome in docker linux container

I have an asp.net core application that uses the jsreport nuget packages to run reports. I am attempting to deploy it with a linux docker container. I seem to be having trouble getting chrome to launch when I run a report. 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.

Here is my full docker file:

#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).

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

Results: Now tests run successfully, without any errors.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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