latest
,85
(Dockerfile)with-node
,85-with-node
,85-with-node-12
(Dockerfile)with-puppeteer
,85-with-puppeteer
(Dockerfile)with-playwright
,85-with-playwright
(Dockerfile)84
,83
,81
,80
,77
,76
,73
,72
,71
,68
,64
84-with-puppeteer
,83-with-puppeteer
,81-with-node
,80-with-node
,77-with-node
,76-with-node
84-with-puppeteer
,83-with-puppeteer
,81-with-puppeteer
,80-with-puppeteer
,77-with-puppeteer
,76-with-puppeteer
Chrome running in headless mode in a tiny Alpine image
We often need a headless chrome. We created this image to get a fully headless chrome image. Be careful to the "--no-sandbox" flag from Chrome
Launching the container using only docker container run -it zenika/alpine-chrome ...
will fail with some logs similar to #33.
Please use the 3 others ways to use Chrome Headless.
Launch the container using:
docker container run -it --rm zenika/alpine-chrome
and use the --no-sandbox
flag for all your commands.
Be careful to know the website you're calling.
Explanation for the no-sandbox
flag in a quick introduction here and for More in depth design document here
Launch the container using:
docker container run -it --rm --cap-add=SYS_ADMIN zenika/alpine-chrome
This allows to run Chrome with sandboxing but needs unnecessary privileges from a Docker point of view.
Thanks to ever-awesome Jessie Frazelle seccomp profile for Chrome. This is The most secure way to run this Headless Chrome docker image.
Also available here wget https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json
Launch the container using:
docker container run -it --rm --security-opt seccomp=$(pwd)/chrome.json zenika/alpine-chrome
The default entrypoint does the following command: chromium-browser --headless --disable-gpu --disable-software-rasterizer --disable-dev-shm-usage
You can get full control by overriding the entrypoint using: docker container run -it --rm --entrypoint "" zenika/alpine-chrome chromium-browser ...
Command (with no-sandbox): docker container run -d -p 9222:9222 zenika/alpine-chrome --no-sandbox --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 https://www.chromestatus.com/
Open your browser to: http://localhost:9222
and then click on the tab you want to inspect. Replace the beginning
https://chrome-devtools-frontend.appspot.com/serve_file/@.../inspector.html?ws=localhost:9222/[END]
by
chrome-devtools://devtools/bundled/inspector.html?ws=localhost:9222/[END]
Command (with no-sandbox): docker container run -it --rm zenika/alpine-chrome --no-sandbox --dump-dom https://www.chromestatus.com/
Command (with no-sandbox): docker container run -it --rm -v $(pwd):/usr/src/app zenika/alpine-chrome --no-sandbox --print-to-pdf --hide-scrollbars https://www.chromestatus.com/
Command (with no-sandbox): docker container run -it --rm -v $(pwd):/usr/src/app zenika/alpine-chrome --no-sandbox --screenshot --hide-scrollbars https://www.chromestatus.com/
Command (with no-sandbox): docker container run -it --rm -v $(pwd):/usr/src/app zenika/alpine-chrome --no-sandbox --screenshot --hide-scrollbars --window-size=1280,1696 https://www.chromestatus.com/
Command (with no-sandbox): docker container run -it --rm -v $(pwd):/usr/src/app zenika/alpine-chrome --no-sandbox --screenshot --hide-scrollbars --window-size=412,732 https://www.chromestatus.com/
Command (with no-sandbox): docker container run -u `id -u $USER` -it --rm -v $(pwd):/usr/src/app zenika/alpine-chrome --no-sandbox --screenshot --hide-scrollbars --window-size=412,732 https://www.chromestatus.com/
Go the deno src
folder. Build your image using this command:
docker image build -t zenika/alpine-chrome:with-deno-sample .
Then launch the container:
docker container run -it --rm zenika/alpine-chrome:with-deno-sample
Download https://deno.land/std/examples/welcome.ts
Warning Implicitly using master branch https://deno.land/std/examples/welcome.ts
Compile https://deno.land/std/examples/welcome.ts
Welcome to Deno π¦
With your own file, use this command:
docker container run -it --rm -v $(pwd):/usr/src/app zenika/alpine-chrome:with-deno-sample run helloworld.ts
Compile file:///usr/src/app/helloworld.ts
Download https://deno.land/std/fmt/colors.ts
Warning Implicitly using master branch https://deno.land/std/fmt/colors.ts
Hello world!
With tool like "Puppeteer", we can add a lot things with our Chrome Headless.
With some code in NodeJS, we can improve and make some tests.
See the "with-puppeteer" folder for more details.
If you have a NodeJS/Puppeteer script in your src
folder named pdf.js
, you can launch it using the following command:
docker container run -it --rm -v $(pwd)/src:/usr/src/app/src --cap-add=SYS_ADMIN zenika/alpine-chrome:with-puppeteer node src/pdf.js
With the "wqy-zenhei" library, you could also manipulate asian pages like in "screenshot-asia.js"
docker container run -it --rm -v $(pwd)/src:/usr/src/app/src --cap-add=SYS_ADMIN zenika/alpine-chrome:with-puppeteer node src/screenshot-asia.js
These websites are tested with the following supported languages:
- Chinese (with
https://m.baidu.com
) - Japanese (with
https://www.yahoo.co.jp/
) - Korean (with
https://www.naver.com/
)
Like "Puppeteer", we can do a lot things using "Playwright" with our Chrome Headless.
Go to the with-playwright
folder and launch the following command:
docker container run -it --rm -v $(pwd)/src:/usr/src/app/src --cap-add=SYS_ADMIN zenika/alpine-chrome:with-playwright node src/useragent.js
A example-chromium.png
file will be created in your with-playwright/src
folder.
By default, this image works with WebGL.
If you want to disable it, make sure to add --disable-gpu
when launching Chromium.
The with-webgl
tag still exists but is deprecated. It will be removed before end of August 2020.
docker container run -it --rm --cap-add=SYS_ADMIN -v $(pwd):/usr/src/app zenika/alpine-chrome --screenshot --hide-scrollbars https://webglfundamentals.org/webgl/webgl-fundamentals.html
docker container run -it --rm --cap-add=SYS_ADMIN -v $(pwd):/usr/src/app zenika/alpine-chrome --screenshot --hide-scrollbars https://browserleaks.com/webgl
Links:
- adieuadieu/serverless-chrome#108
- DevExpress/testcafe#2116
- 'use-gl' values here
We can run the container as root with this command:
docker container run --rm -it --entrypoint "" --user root zenika/alpine-chrome sh
Some examples are available on the examples
directory:
- docker-compose to launch a chrome calling a nginx server in the same docker-compose
- x11 to experiment this image with a X11 server.
-
Headless Chrome website: https://developers.google.com/web/updates/2017/04/headless-chrome
-
List of all options of the "Chromium" command line: https://peter.sh/experiments/chromium-command-line-switches/
-
Where to file issues: https://github.com/Zenika/alpine-chrome/issues
-
Maintained by: https://www.zenika.com
docker container run -it --rm --entrypoint "" zenika/alpine-chrome cat /etc/alpine-release
3.12.0
docker container run -it --rm --entrypoint "" zenika/alpine-chrome chromium-browser --version
Chromium 85.0.4183.83
docker image inspect zenika/alpine-chrome --format='{{.Size}}'
407451915
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
βοΈ this repo or leave a comment here
π Support this repository using GitHub Sponsor