The headless-shell project provides a Docker image,
chromedp/headless-shell, containing a pre-built
version of Chrome's
headless-shell -- a slimmed down version of Chrome that
is useful for driving, profiling, or testing web pages.
The version of
headless-shell contained in this Docker image has been
modified from the original Chromium source tree, to report the same user agent
as Chrome, and has had other minor modifications made to it in order make it
better suited for use in an embedded context.
You can use this Docker image in the usual way:
# pull latest version of headless-shell $ docker pull chromedp/headless-shell:latest # pull specific tagged version of headless-shell $ docker pull chromedp/headless-shell:74.0.3717.1 # run $ docker run -d -p 9222:9222 --rm --name headless-shell chromedp/headless-shell # if headless-shell is crashing with a BUS_ADRERR error, pass a larger shm-size: $ docker run -d -p 9222:9222 --rm --name headless-shell --shm-size 2G chromedp/headless-shell # run as unprivileged user # get seccomp profile from https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json $ docker run -d -p 9222:9222 --user nobody --security-opt seccomp=chrome.json --entrypoint '/headless-shell/headless-shell' chromedp/headless-shell --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222 --disable-gpu --headless
Using as a base image
chromedp/headless-shell as a base image to build an image that runs your own program, You could experience zombie process problem. To reap zombie processeses, use
tini on your
FROM chromedp/headless-shell:latest ... # Install dumb-init or tini RUN apt install dumb-init # or RUN apt install tini ... ENTRYPOINT ["dumb-init", "--"] # or ENTRYPOINT ["tini", "--"] CMD ["/path/to/your/program"]
If running Docker 1.13.0 or later, use
--init arg instead to reap zombie processes.
docker run -d -p <PORT>:<PORT> --name <your-program> --init <your-image>
Building and Packaging
The following contains instructions for building and packaging the
chromedp/headless-shell Docker image manually.
Setup and Building
If you'd like to build this image yourself, locally, you will need to build
headless-shell manually from the Chromium source. As such you will need to
depot_tools, your build environment, and a full checkout of
the Chromium source tree and its related dependencies.
Please see the following for instructions on building Chromium and
headless-shell on Linux:
Before proceeding, please ensure you have fully completed the above, have
headless-shell at least once, and that your Chromium source
tree is up-to-date.
After you are able to successfully build
headless-shell directly from the
Chromium source tree, you can simply run
# build headless-shell $ ./build-headless-shell.sh /path/to/chromium/src 74.0.3717.1 # build docker image (uses $PWD/out/headless-shell-$VER.tar.bz2) $ ./build-docker.sh 74.0.3717.1