├── latest ├── docker-compose.test.yml └── Dockerfile ├── .editorconfig ├── LICENSE └── README.md /latest/docker-compose.test.yml: -------------------------------------------------------------------------------- 1 | sut: 2 | build: . 3 | command: sh -c '(phantomjs --webdriver=8910 &) && sleep 5 && curl --connect-timeout 5 --silent --show-error --fail http://localhost:8910/wd/hub/status' 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 ServeBox 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /latest/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:buster-slim 2 | 3 | ARG PHANTOM_JS_VERSION 4 | ARG DUMB_INIT_VERSION 5 | 6 | # https://bitbucket.org/ariya/phantomjs/downloads/ 7 | ENV PHANTOM_JS_VERSION ${PHANTOM_JS_VERSION:-2.1.1-linux-x86_64} 8 | 9 | # Install runtime dependencies 10 | RUN apt-get update \ 11 | && apt-get install -y --no-install-recommends \ 12 | ca-certificates \ 13 | curl \ 14 | bzip2 \ 15 | libfontconfig \ 16 | && apt-get clean \ 17 | && rm -rf /var/lib/apt/lists/* 18 | 19 | # https://github.com/Yelp/dumb-init/releases 20 | ENV DUMB_INIT_VERSION ${DUMB_INIT_VERSION:-1.2.2} 21 | 22 | RUN set -x \ 23 | # Install official PhantomJS release 24 | && mkdir /tmp/phantomjs \ 25 | && curl -Ls https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${PHANTOM_JS_VERSION}.tar.bz2 \ 26 | | tar -xj --strip-components=1 -C /tmp/phantomjs \ 27 | && mv /tmp/phantomjs/bin/phantomjs /usr/local/bin \ 28 | # Install dumb-init (to handle PID 1 correctly). 29 | && curl -Lso /tmp/dumb-init.deb https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64.deb \ 30 | && dpkg -i /tmp/dumb-init.deb 31 | 32 | # PhantomJS requires an OpenSSL config even if it's an empty one, 33 | # else it'll complain about "libssl_conf.so: cannot open shared object file" 34 | # which seems to be a recent bug. 35 | ENV OPENSSL_CONF=/opt/openssl.cnf 36 | 37 | RUN set -x \ 38 | # Runs as non-root user. 39 | && useradd --system --uid 52379 -m --shell /usr/sbin/nologin phantomjs \ 40 | && touch /opt/openssl.cnf \ 41 | # Basic test. 42 | && su phantomjs -s /bin/sh -c "dumb-init phantomjs --version" 43 | 44 | USER phantomjs 45 | 46 | EXPOSE 8910 47 | 48 | ENTRYPOINT ["dumb-init"] 49 | CMD ["phantomjs"] 50 | 51 | # NOTE: The healthcheck only makes sense if it's started with --webdriver=8910 52 | #HEALTHCHECK --interval=5s --timeout=2s --retries=20 \ 53 | # CMD curl --connect-timeout 5 --silent --show-error --fail http://localhost:8910/wd/hub/status || exit 1 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Supported tags and respective `Dockerfile` links 2 | 3 | * [`latest`](https://github.com/wernight/docker-phantomjs/blob/master/latest/Dockerfile) built from the [latest PhantomJS snapshot](https://github.com/ariya/phantomjs/commits/master) [![](https://images.microbadger.com/badges/image/wernight/phantomjs.svg)](http://microbadger.com/images/wernight/phantomjs "Get your own image badge on microbadger.com") 4 | * [`2`, `2.1`, `2.1.1`](https://github.com/wernight/docker-phantomjs/blob/v2.1.1/Dockerfile) [![](https://images.microbadger.com/badges/image/wernight/phantomjs:2.1.svg)](http://microbadger.com/images/wernight/phantomjs "Get your own image badge on microbadger.com") 5 | * [`2.0`, `2.0.0`](https://github.com/wernight/docker-phantomjs/blob/v2.0.0/Dockerfile) [![](https://images.microbadger.com/badges/image/wernight/phantomjs:2.0.svg)](http://microbadger.com/images/wernight/phantomjs "Get your own image badge on microbadger.com") 6 | * [`1`, `1.9`, `1.9.7`](https://github.com/wernight/docker-phantomjs/blob/v1.9.7/Dockerfile) [![](https://images.microbadger.com/badges/image/wernight/phantomjs:1.svg)](http://microbadger.com/images/wernight/phantomjs "Get your own image badge on microbadger.com") 7 | 8 | ## What is PhantomJS 9 | 10 | [PhantomJS][phantomjs] is a headless WebKit browser, often used via [WebDriver][webdriver] for web system testing. 11 | It's based on WebKit, runs JavaScript, and allows to take screenshots. 12 | 13 | 14 | ## Features of this image 15 | 16 | This [Dockerized][docker] version of PhantomJS is: 17 | 18 | * **Small**: Using [Debian image][debian] (below 100 MB, while Ubuntu is about 230 MB), and removing packages used during build. 19 | * **Simple**: Exposes default port, easy to extend. 20 | * **Secure**: Runs as non-root UID/GID `52379` (selected randomly to avoid mapping to an existing user) and uses [dumb-init](https://github.com/Yelp/dumb-init) to reap zombie processes. 21 | 22 | 23 | ## Usage 24 | 25 | ### JavaScript interactive shell 26 | 27 | Start PhantomJS in [REPL](http://phantomjs.org/repl.html): 28 | 29 | $ docker run -it --rm wernight/phantomjs 30 | > 31 | 32 | ### Remote WebDriver 33 | 34 | Start as 'Remote WebDriver mode' (embedded [GhostDriver](https://github.com/detro/ghostdriver)): 35 | 36 | $ docker run -d -p 8910:8910 wernight/phantomjs phantomjs --webdriver=8910 37 | 38 | To connect to it (some examples per language): 39 | 40 | * Java: 41 | 42 | WebDriver driver = new RemoteWebDriver( 43 | new URL("http://127.0.0.1:8910"), 44 | DesiredCapabilities.phantomjs()); 45 | 46 | * Python (after running [`$ pip install selenium`](https://pypi.python.org/pypi/selenium/)): 47 | 48 | from selenium import webdriver 49 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 50 | 51 | driver = webdriver.Remote( 52 | command_executor='http://127.0.0.1:8910', 53 | desired_capabilities=DesiredCapabilities.PHANTOMJS) 54 | 55 | driver.get('http://example.com') 56 | driver.find_element_by_css_selector('a[title="hello"]').click() 57 | 58 | driver.quit() 59 | 60 | 61 | ## Feedbacks 62 | 63 | Improvement ideas and pull requests are welcome via 64 | [Github Issue Tracker](https://github.com/wernight/docker-phantomjs/issues). 65 | 66 | [phantomjs]: http://phantomjs.org/ 67 | [docker]: https://www.docker.io/ 68 | [debian]: https://registry.hub.docker.com/_/debian/ 69 | [webdriver]: http://www.seleniumhq.org/projects/webdriver/ 70 | --------------------------------------------------------------------------------