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```
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.
Related
The following Dockerfile does not build (docker build .), and causes undefined error code 199. my-app folder was created with ng new my-app. This I believe is due to protractor chrome-driver not knowing where chromium is installed. I then tried to set ENV variable, with no change.
How do I download chrome, install and set properties correctly so to build the docker container?
FROM node:alpine
ADD my-app ./my-app
RUN apk update && \
apk upgrade && \
apk add --no-cache openjdk8 && \
apk --no-cache add curl && \
apk --no-cache add bash && \
#apk --no-cache add chromium && \
npm install -g protractor && \
webdriver-manager update
ENV CHROME_BIN=/usr/bin/chromium-browser
RUN cd ./my-app && npm run e2e
I have a script in my automation tests (built using protractor(5.4.0) and runs on Headless Chrome in Circle CI using Docker) which installs currently the latest chrome browser for me:
apt-get update && apt-get -y install libxss1 libappindicator1 libindicator7
curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i ./google-chrome*.deb
apt-get install -yf
This script downloads me the latest chrome browser version available.
Is there any way to get older version of chrome.deb and install via curl as there are few things I suspect aren't running since chrome updated and I would like to test with a older version once.
I found few older browser versions to install on websites like slimjet, ubunutu but would like to know if I can get it via https://dl.google.com or if there is any better way to do this.
For deb package at Ubuntu - Chrome:
CHROME_VERSION=77.0.3865.120-1
wget --no-check-certificate https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb
dpkg -i google-chrome-stable_${CHROME_VERSION}_amd64.deb || apt -y -f install
rm google-chrome-stable_${CHROME_VERSION}_amd64.deb;
For Chromium:
For more info about old Chromium, please refer to: https://github.com/Bugazelle/chromium-all-old-stable-versions
CHROMIUM_VERSION=77.0.3865.120
wget --no-check-certificate https://raw.githubusercontent.com/Bugazelle/chromium-all-old-stable-versions/master/chromium.stable.json
download=$(jq -r ".linux64.\"${CHROMIUM_VERSION}\".download_url" chromium.stable.json)
position=$(jq -r ".linux64.\"${CHROMIUM_VERSION}\".download_position" chromium.stable.json)
echo "download url is: ${download}"
echo "position is: ${position}"
wget --no-check-certificate -O chromium.zip ${download}
ENV CHROME_VERSION "99.0.4844.84-1"
RUN set -ex && \
apt-get update -qqy && \
wget --no-check-certificate https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${CHROME_VERSION}_amd64.deb && \
apt-get install -qqyf ./google-chrome-stable_${CHROME_VERSION}_amd64.deb && \
rm google-chrome-stable_${CHROME_VERSION}_amd64.deb
I am trying to install google chrome in docker build with following standard way:
ARG CHROME_VERSION="google-chrome-stable"
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-chrome.list \
&& apt-get update -qqy \
&& apt-get -qqy install \
${CHROME_VERSION:-google-chrome-stable} \
&& rm /etc/apt/sources.list.d/google-chrome.list \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
But my proxy does not allow google.com so it fails. Is there other way to install google chrome in ubuntu? I don't want to host any file in network so if there is another source (e.g. github) where I can find debian packages for chrome then I can just get that and run that with dpkg. Or, any other idea?
Thanks a lot.
I found a mirror in my network. Replacing source with my mirror, job was done!
I've been trying for the last two days to get chromuim installed and running on docker:latest docker image. (docker in docker).
I have tried multiple docker files:
from docker:latest
RUN apk add --no-cache python py2-pip curl bash chromuim ttf-freefont xvfb nodejs nodejs-npm udev
RUN curl -sSL https://sdk.cloud.google.com | bash
ENV PATH $PATH:~/google-cloud-sdk/bin
RUN pip install docker-compose
RUN npm install -g #angular/cli swagger
ENV CHROME_BIN=/usr/bin/chromium-browser
This installed chrome 57, which doesn't support headless.
So I suspect I can run this with xvbf, but running this chrome fails with:
Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
[8:8:1124/085514.600081:FATAL:zygote_host_impl_linux.cc(182)] Check failed: ReceiveFixedMessage(fds[0], kZygoteBootMessage, sizeof(kZygoteBootMessage), &boot_pid).
Aborted (core dumped)
So I tried to install chrome 61 (which supported headless).
But for that you need to update the Dockerfile to use edge.
I tried to upgrade / or install 61 right away. I always get fonts missing.
The closest I got was adjusting my dockerfile to use lighthose one
from docker:latest
RUN apk add --no-cache python py2-pip curl bash xvfb nodejs nodejs-npm udev
RUN curl -sSL https://sdk.cloud.google.com | bash
ENV PATH $PATH:~/google-cloud-sdk/bin
RUN pip install docker-compose
RUN npm install -g #angular/cli swagger
ENV CHROME_BIN=/usr/bin/chromium-browser
USER root
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
#-----------------
# Set ENV and change mode
#-----------------
ENV LIGHTHOUSE_CHROMIUM_PATH /usr/bin/chromium-browser
ENV TZ "Europe/Berlin"
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
ENV SCREEN_WIDTH 750
ENV SCREEN_HEIGHT 1334
ENV SCREEN_DEPTH 24
ENV DISPLAY :99.0
ENV PATH /lighthouse/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV GEOMETRY "$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
RUN echo $TZ > /etc/timezone
#-----------------
# Add packages
#-----------------
RUN apk -U --no-cache update
RUN apk -U --no-cache add \
zlib-dev \
chromium \
freetype \
ttf-opensans \
xvfb \
wait4ports \
xorg-server \
dbus \
ttf-freefont \
mesa-dri-swrast
# Minimize size
RUN apk del --purge --force curl make gcc g++ python linux-headers binutils-gold gnupg git zlib-dev apk-tools libc-utils
RUN rm -rf /var/lib/apt/lists/* \
/var/cache/apk/* \
/usr/share/man \
/tmp/* \
/usr/lib/node_modules/npm/man \
/usr/lib/node_modules/npm/doc \
/usr/lib/node_modules/npm/html \
/usr/lib/node_modules/npm/scripts
VOLUME /lighthouse/output
ADD xvfb-chromium.sh /chromium-xvfb.sh
RUN chmod +x /chromium-xvfb.sh
xvfb-chromium.sh (althought not need, as you can docker run /bin/bash into the container)
#!/bin/sh
_kill_procs() {
kill -TERM $chromium
wait $chromium
kill -TERM $xvfb
}
parameters=$#
# We need to test if /var/run/dbus exists, since script will fail if it does not
[ ! -e /var/run/dbus ] && mkdir /var/run/dbus
/usr/bin/dbus-daemon --system
# Setup a trap to catch SIGTERM and relay it to child processes
trap _kill_procs SIGTERM
TMP_PROFILE_DIR=`mktemp -d -t chromium.XXXXXX`
export CHROME_DEBUGGING_PORT=9222
# Start Xvfb
Xvfb ${DISPLAY} -ac +iglx -screen 0 ${GEOMETRY} -nolisten tcp & xvfb=$!
printf "Starting xvfb window server..."
while [ 1 -gt $xvfb ]; do printf "..."; sleep 1; done
printf "xvfb started\n\n"
#printf "Starting chromium, with debugger on port $CHROME_DEBUGGING_POST...\n\n"
# --disable-webgl \
$CHROME_BIN \
--no-sandbox \
--user-data-dir=${TMP_PROFILE_DIR} \
--start-maximized \
--remote-debugging-port=${CHROME_DEBUGGING_PORT} \
--no-first-run "about:blank" &
#chromium=$!
#wait4ports tcp://127.0.0.1:$CHROME_DEBUGGING_PORT
printf "\n\n==============================\nlaunching lighthouse run\n==============================\n\n"
#wait $chromium
wait $xvfb
Then I got another error:
Error relocating /usr/lib/chromium/chrome: FT_Set_Default_Properties: symbol not found
Not sure how to solve this, any help would be appreciated.
you could try this link https://github.com/c0b/chrome-in-docker
It downloads a google-chrome Linux version from chrome channels, either stable, or beta, or developer version;It turns google-chrome into a headless browser,
I'm using official docker images for PHP 7 (7.0.3-Apache) and MySql (5.7.10).
Using docker-compose, created containers from images and linked both.
Copied php.ini from https://github.com/php/php-src/blob/php-7.0.3/php.ini-production, replaced dll extensions with so and placed that file in /usr/local/etc/php and enabled _pdo_mysql_ extension in it.
extension=php_pdo_mysql.so
phpinfo shows php.ini loaded but not pdo_mysql extension because it's not installed.
I googled and tried different extension names with apt-get install:
php-mysql, php7-mysql, php7.0-mysql, php7.0.3-mysql.
None of them works. Error says: E: Unable to locate package.
With php5-mysql, it's get installed but after restarting apache with command: docker kill --signal="USR1" <container-name>, extension doesn't show loaded in php.ini.
(Don't think it's much related to docker but I'm new to docker and trying with that now, so mentioning it here.)
Can anyone help to configure pdo_mysql extension with php7-Apache?
You need the Dotdeb repository in /etc/apt/sources.list on your docker image:
FROM php:7-apache
# Install pdo_mysql
RUN apt-get update \
&& echo 'deb http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list \
&& echo 'deb-src http://packages.dotdeb.org jessie all' >> /etc/apt/sources.list \
&& apt-get install -y wget \
&& wget https://www.dotdeb.org/dotdeb.gpg \
&& apt-key add dotdeb.gpg \
&& apt-get update \
&& apt-get install -y php7.0-mysql \
&& docker-php-ext-install pdo_mysql