Skip to content
Minimal container for Chrome's headless shell, useful for automating / driving the web
Shell Dockerfile
Branch: master
Clone or download

README.md

About headless-shell

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.

Notably, this Docker image has been created expressly for the Go chromedp package, which provides a simple and easy to use API for driving browsers compatible with the Chrome Debugging Protocol.

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.

Running

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

When using 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 dumb-init or tini on your Dockerfile's ENTRYPOINT

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 docker run's --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 setup Chromium's 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 manually built headless-shell at least once, and that your Chromium source tree is up-to-date.

Building

After you are able to successfully build headless-shell directly from the Chromium source tree, you can simply run build-docker.sh:

# 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
You can’t perform that action at this time.