schickling / chromeless

🖥 Chrome automation made simple. Runs locally or headless on AWS Lambda.
https://chromeless.netlify.com
MIT License
13.25k stars 575 forks source link

Chromeless docker container #25

Open voltcode opened 7 years ago

voltcode commented 7 years ago

It would be great to quickly spin up a farm of chromeless images to run a test suite in parallel. Using containers would remove the AWS requirement for scalability. I'm not a docker expert, just started to evaluate docker-based solution as our test suite has grown significantly in the last couple of months, and we need a more elastic approach.

neekolas commented 7 years ago

I can make a PR for something similar to this Dockerfile. It works in my extremely limited testing. Should it go in the examples folder?

https://github.com/neekolas/chromeless-testbed/blob/feature/docker/Dockerfile

heww commented 6 years ago

@voltcode https://github.com/joelgriffith/browserless#usage-with-chromeless may works!

stephanedebove commented 6 years ago

I can make a PR for something similar to this Dockerfile. It works in my extremely limited testing. Should it go in the examples folder?

https://github.com/neekolas/chromeless-testbed/blob/feature/docker/Dockerfile

how can this dockerfile work you don't even install chromeless in it?

stephanedebove commented 6 years ago

So after MANY days of searching I'm finally unable to run my Chromeless script in Docker. Here is the dockerfile I use:

FROM ubuntu:16.04
WORKDIR /app
RUN apt-get update
RUN apt-get install curl -y

# Install Node.js
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash
RUN apt-get install --yes nodejs wget dos2unix udev ttf-freefont
RUN node -v
RUN npm -v

# install chromeless
COPY package.json /app/package.json
RUN npm install chromeless

#INSTALL CHROME:
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 && \
  apt-get update && \
  apt-get install -y google-chrome-stable && \
rm -rf /var/lib/apt/lists/*

Just build this image docker build -t chromeless-image ., and run it with docker run -it -v yourpath:/app chromeless-image /bin/bash, with yourscript.js in yourpath. Then you just need to launch Chrome google-chrome --headless --remote-debugging-port=9222 --disable-gpu --no-sandbox & before launching your chromeless script node yourscript.js and it should be fine.

It's not working 100% though. I have found that when trying to access some websites (which ones exactly I don't know) I run into the errors

[1104/111344.440167:ERROR:bus.cc(394)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[1104/111344.440313:WARNING:property.cc(149)] DaemonVersion: GetAndBlock: failed.
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'

and a bunch of other errors. I have no idea where these errors are coming from.