1

I had installed chromedp locally using this usual way:- $ go get -u github.com/chromedp/chromedp. I am able to run it locally but when I deployed it to my stage environment, I got below error:-

exec: \"google-chrome\": executable file not found in $PATH

What changes do I need to make in my dockerfile?

Note: I have already tried adding below code in my Dockerfile as suggested in this answer, still doesn't work


RUN apk update && apk upgrade && apk add --no-cache bash git && apk add --no-cache chromium

# Installs latest Chromium package.
RUN echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories \
    && echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories \
    && apk add --no-cache \
    harfbuzz@edge \
    nss@edge \
    freetype@edge \
    ttf-freefont@edge \
    && rm -rf /var/cache/* \
    && mkdir /var/cache/apk

RUN go get github.com/mafredri/cdp


CMD chromium-browser --headless --disable-gpu --remote-debugging-port=9222 --disable-web-security --safebrowsing-disable-auto-update --disable-sync --disable-default-apps --hide-scrollbars --metrics-recording-only --mute-audio --no-first-run --no-sandbox```
Umesh Malhotra
  • 967
  • 1
  • 10
  • 25

1 Answers1

0

It took me a while to figure out this problem originally, it's not just you. When your installing chromedp on your local machine it's grabbing the package and building for that specific distro. When you run it inside docker you need to download a specific chromium build for the distro you are running inside docker. This is because deb is different than rpm is different than alpine and you need to have the right chromium.

Here is a copy of my docker file using a basic linux distro

RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | 
apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> 
/etc/apt/sources.list.d/google.list
RUN apt-get update && apt-get -y install google-chrome-stable
RUN chrome &
WORKDIR /app/svc/worker
RUN go build -o main .
EXPOSE 6061
CMD ["./main"]

This version for Alpine might work https://pkgs.alpinelinux.org/packages?name=chromium&branch=v3.10. However, in my experience it is best not to go with a minimal distro because chrome might depend on features not included in alpine.

notdamama
  • 1
  • 1
  • Hi @notdamama. I am getting this error - failed to create LLB definition: dockerfile parse error line 6: unknown instruction: APT-KE – Umesh Malhotra Sep 23 '21 at 15:06
  • It's not advertised much - though I think it absolutely should be - but indeed chromedp requires some Chromium-like browser to be in your $PATH, as can be seen here: https://github.com/chromedp/chromedp/blob/3f81ff8463df931d8f1c2574610b62660c06a01d/allocate.go#L342 Make sure that your container has it in $PATH, you can do that by exec-ing into your container and trying to start the browser. – filmil Sep 29 '21 at 05:11