How to create a Docker with Jenkins, CaspesJS, PhantomJS and ChromeDriver

Create a Dockerfile with this content:

FROM jenkins

RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && apt-get update && apt-get install -y google-chrome-stable

RUN /usr/local/bin/install-plugins.sh ace-editor  ant antisamy-markup-formatter branch-api build-timeout cloudbees-folder credentials credentials-binding chromedriver  durable-task email-ext external-monitor-job git git-client github github-api github-branch-source github-organization-folder git-server gradle handlebars icon-shim javadoc jquery-detached junit ldap mailer mapdb-api matrix-auth matrix-project momentjs pam-auth pipeline-build-step pipeline-input-step pipeline-rest-api pipeline-stage-step pipeline-stage-view plain-credentials scm-api script-security ssh-credentials ssh-slaves structs subversion timestamper token-macro windows-slaves workflow-aggregator workflow-api workflow-basic-steps workflow-cps workflow-cps-global-lib workflow-durable-task-step workflow-job workflow-multibranch workflow-scm-step workflow-step-api workflow-support ws-cleanup

USER root
 RUN apt-get clean && apt-get update && apt-get install -y npm build-essential chrpath libssl-dev libxft-dev libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev

RUN cd ~ && wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 && tar xvfj phantomjs-2.1.1-linux-x86_64.tar.bz2 && rm phantomjs-2.1.1-linux-x86_64.tar.bz2 && mv phantomjs-2.1.1-linux-x86_64 /usr/local/share && ln -sf /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin && npm install -g casperjs

Explanation

Dockerfile first RUN

On the first RUN we’ll install the google-chrome for use with the ChromeDriver plugin on Jenkins.

Dockerfile second RUN

Here we’ll installed all the plugins we use on Jenkins.

Dockerfile next RUN

The third RUN we’ll install all packages we’ll need for the last version of phantomjs.

Dockerfile last RUN

In this RUN we download the last version of phantom and install it, then install casperjs using npm.

Build and run the new Jenkins Docker

docker build -t lcjenkins .
docker run --name lcjenkins -p 8888:8080 -p 50000:50000 -v $jhome:/var/jenkins_home tgjenkins

* Change the $jhome for the path you want to have the jenkins home.