dockerselenium-webdriverdockerfileazure-functionspuppeteer-sharp

Launch PuppeteerSharp or Selenium in a Azure Function on docker


web scraper and azure function, I'm trying to get information from a website using puppettersharp or selenium webdriver, when I'm launching this dockerfile and running the docker it places me in root-like : root@randomnumber and I don't understand why Dockerfile =

FROM mcr.microsoft.com/azure-functions/dotnet:4-dotnet6-core-tools`
`# Start installation`
`RUN apt-get -y update && apt-get install -yqq unzip && apt-get install -yqq wget && apt-get install -yqq curl`
`RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb`
`RUN apt upgrade -y && apt install -y ./google-chrome-stable_current_amd64.deb`
`RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/ curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE/chromedriver_linux64.zip`
`RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/`
`#End installation`

`COPY . /src/dotnet-function-app`
`RUN cd /src/dotnet-function-app && mkdir -p /home/site/wwwroot && dotnet publish *.csproj --output /home/site/wwwroot`

moreover, when I'm using this default docker file it's saying no chromedriver while I'm downloading it Dockerfile default dockerfile

here is the c# code for the selenium function and when I'm executing it with the default it's saying no chromedriver selenium code

here is the c#code for puppeteersharp and when I'm executing it's saying failed to launch a browser and I don't understand why puppeteersharp code

when launched locally it works, I hope someone can help me thx in advance


Solution

  • You need to set the Env path of chrome in the dockerfile

    FROM mcr.microsoft.com/azure-functions/dotnet:4-dotnet6-core-tools`
    `# Start installation`
    `RUN apt-get -y update && apt-get install -yqq unzip && apt-get install -yqq wget && apt-get install -yqq curl`
    `RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb`
    `RUN apt upgrade -y && apt install -y ./google-chrome-stable_current_amd64.deb`
    `RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/ curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE/chromedriver_linux64.zip`
    `RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/`
    `#End installation`
    
    ## the set the environment path 
    ENV PATH="/usr/local/bin/chromedriver:${PATH}"
    
    `COPY . /src/dotnet-function-app`
    `RUN cd /src/dotnet-function-app && mkdir -p /home/site/wwwroot && dotnet publish *.csproj --output /home/site/wwwroot`
    ```
    
    change the chrome path in C# code to
     
    ```/usr/local/bin/chromedriver```