Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing phantomjs with node in docker

I'm trying to install the phantomjs executable in /usr/local/bin in a docker container, alongside node. I think I'm almost there, but I'm pretty new to docker and not well versed in installing binaries or working with Linux so struggling to work out where I'm going wrong.

This is my docker file:

FROM        node:6.4-onbuild

# Install phantomjs
WORKDIR     ~
RUN         apt-get install libfreetype6 libfreetype6-dev \
            && apt-get install libfontconfig1 libfontconfig1-dev
RUN         export PHANTOM_JS="phantomjs-2.1.1-linux-i686" \
            && wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2 \
            && tar xvjf $PHANTOM_JS.tar.bz2 \
            && mv $PHANTOM_JS /usr/local/share \
            && ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin

WORKDIR     /usr/src/app
RUN         npm run build
EXPOSE      8080
CMD         ["node", "./bin/start.js"]

I've run bash on the container and there is definitely something called phantomjs in /usr/local/bin but I'm assuming that I've linked the wrong thing or it's an invalid executable. I'm thrown an error from my application telling me that there is no phantomjs executable in /usr/local/bin.

Can anyone give me a few pointers? Happy to provide more details if you post a comment.

like image 503
Isaac Avatar asked Sep 12 '16 13:09

Isaac


2 Answers

We solved using the following docker file

FROM ubuntu:latest

WORKDIR /opt/backend
RUN su -
RUN  apt-get update
RUN apt-get install sudo -y
RUN sudo apt install curl -y
RUN curl -sL https://deb.nodesource.com/setup_17.x -o nodesource_setup.sh
RUN sudo bash nodesource_setup.sh
RUN sudo apt install nodejs -y 
RUN sudo apt-get install -y fontconfig
RUN sudo apt-get install -y libfontconfig

COPY . .
# Rference [https://github.com/Medium/phantomjs#linux-note][1]
RUN sudo npm set strict-ssl false
RUN sudo npm install 
RUN sudo npm install -g phantomjs-prebuilt 
RUN sudo npm install -g html-pdf 

RUN sudo npm rebuild
RUN sudo npm run build

EXPOSE 3005
CMD npm run start:$env_Profile
like image 129
Ehab Qadah Avatar answered Sep 30 '22 23:09

Ehab Qadah


There's an existing image for this already on Docker hub using the following Dockerfile:

FROM debian:jessie 
  MAINTAINER Werner Beroux <[email protected]> 
  # 1. Install runtime dependencies 
  # 2. Install official PhantomJS release 
  # 3. Clean up 

  RUN apt-get update \
      && apt-get install -y --no-install-recommends \
          ca-certificates \
          bzip2 \
          libfontconfig \
      && apt-get clean \
      && rm -rf /var/lib/apt/lists/*
  
  RUN apt-get update \
      && apt-get install -y --no-install-recommends \
          curl \
      && mkdir /tmp/phantomjs \
      && curl -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 \
              | tar -xj --strip-components=1 -C /tmp/phantomjs \
      && cd /tmp/phantomjs \
      && mv bin/phantomjs /usr/local/bin \
      && cd \
      && apt-get purge --auto-remove -y \
          curl \
      && apt-get clean \
      && rm -rf /tmp/* /var/lib/apt/lists/*
  
  # Run as non-root user 
  RUN useradd --system --uid 72379 -m --shell /usr/sbin/nologin phantomjs
  
  USER phantomjs 
  EXPOSE 8910 
  CMD ["/usr/local/bin/phantomjs"]
like image 38
BMitch Avatar answered Sep 30 '22 21:09

BMitch