Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PhantomJS on Alpine (Docker)
# 1: Use node 6 as base:
FROM node:6-alpine
# 2: Download+Install PhantomJS, as the npm package 'phantomjs-prebuilt' won't work on alpine!
# See https://github.com/dustinblackman/phantomized
RUN set -ex \
&& apk add --no-cache --virtual .build-deps ca-certificates openssl \
&& wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1/dockerized-phantomjs.tar.gz" | tar xz -C / \
&& npm install -g phantomjs \
&& apk del .build-deps
@vikashvikram

This comment has been minimized.

Copy link

vikashvikram commented Jan 31, 2018

This was a great help. Thanks 👍

@CoreyCole

This comment has been minimized.

Copy link

CoreyCole commented Jun 5, 2018

@vovimayhem not working for me on node:8.11-alpine any ideas?

Looks like an `npm install -g`
Error checking path, continuing { Error: Cannot find module '/usr/local/lib/node_modules/phantomjs/lib/location'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at getLocationInLibModuleIfMatching (/usr/local/lib/node_modules/phantomjs/install.js:332:19)
    at Promise._successFn (/usr/local/lib/node_modules/phantomjs/install.js:389:28)
    at nextTickCallback (/usr/local/lib/node_modules/phantomjs/node_modules/kew/kew.js:47:28)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9) code: 'MODULE_NOT_FOUND' }
/usr/local/lib/node_modules/phantomjs/phantomjs is not writable: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/phantomjs/phantomjs'
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1//phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...

Received 22866K total.
Extracting tar contents (via spawned process)
Removing /usr/local/lib/node_modules/phantomjs/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1528239728488/phantomjs-2.1.1-linux-x86_64 -> /usr/local/lib/node_modules/phantomjs/lib/phantom
Phantom installation failed { Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1528239728488/phantomjs-2.1.1-linux-x86_64' -> '/usr/local/lib/node_modules/phantomjs/lib/phantom'
  errno: -13,
  code: 'EACCES',
  syscall: 'link',
  path: '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1528239728488/phantomjs-2.1.1-linux-x86_64',
  dest: '/usr/local/lib/node_modules/phantomjs/lib/phantom' } Error: EACCES: permission denied, link '/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1528239728488/phantomjs-2.1.1-linux-x86_64' -> '/usr/local/lib/node_modules/phantomjs/lib/phantom'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs@2.1.7 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the phantomjs@2.1.7 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-06-05T23_02_12_191Z-debug.log
The command '/bin/sh -c set -ex     && apk add --no-cache --virtual .build-deps ca-certificates openssl     && wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1/dockerized-phantomjs.tar.gz" | tar xz -C /     && npm install -g phantomjs     && apk del .build-deps' returned a non-zero code: 1
@CoreyCole

This comment has been minimized.

Copy link

CoreyCole commented Jun 5, 2018

Needed curl, this worked for me

RUN apk update && apk add --no-cache fontconfig curl curl-dev && \
    mkdir -p /usr/share && \
    cd /usr/share \
    && curl -L https://github.com/Overbryd/docker-phantomjs-alpine/releases/download/2.11/phantomjs-alpine-x86_64.tar.bz2 | tar xj \
    && ln -s /usr/share/phantomjs/phantomjs /usr/bin/phantomjs \
    && phantomjs --version
@CoreyCole

This comment has been minimized.

Copy link

CoreyCole commented Jun 5, 2018

@Tasuja

This comment has been minimized.

Copy link

Tasuja commented Feb 26, 2019

Adding this to dockerfile worked for me:

ENV PHANTOMJS_VERSION 2.1.1

RUN apk add --update --no-cache curl &&
curl -Ls "https://github.com/dustinblackman/phantomized/releases/download/${PHANTOMJS_VERSION}/dockerized-phantomjs.tar.gz" | tar xz -C / && \
curl -k -Ls https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${PHANTOMJS_VERSION}-linux-x86_64.tar.bz2 | tar -jxvf - -C / &&
cp phantomjs-${PHANTOMJS_VERSION}-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs &&
rm -fR phantomjs-${PHANTOMJS_VERSION}-linux-x86_64 &&
apk del curl

Source: https://hub.docker.com/r/wangqiru/phantomjs/dockerfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.