I wrote an application in C# which need to use a browser instance like chrome. I dockerized the application and the run using:
sudo docker run -d --name myapp --restart=always -e BROWSER_PATH=/usr/bin/chromium-browser myimage
The application start correctly but I get the following error:
Unhandled Exception: System.AggregateException: One or more errors occurred. (Failed to launch browser! path to executable does not exist) ---> System.IO.FileNotFoundException: Failed to launch browser! path to executable does not exist
seems that the Docker
container cannot access to the browser folder which is located outside of the container.
I'm using puppeteer-sharp
to manage the browser, so the lines which is throwing the error is the folling:
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath = Environment.GetEnvironmentVariable("BROWSER_PATH"),
});
as you can see I'm reading the BROWSER_PATH
from an environment variable.
How can I fix this?
Thanks.
UPDATE:
I tried to mount the volume as suggested using:
sudo docker run -d --name myapp --restart=always -e BROWSER_PATH=/usr/bin/chromium-browser --v "/$(pwd)/usr/bin/chromium-browser:/usr/bin/chromium-browser" myimage
but I get the same error:
Failed to launch browser! path to executable does not exist
what I did wrong?
You need to mount them in container. https://flaviocopes.com/docker-access-files-outside-container/