Forum How do I...?

Docker Image for prince

sailorxyz
Is there an official Docker image for Princexml or a recommended one. Failing that, what do I need to know to make my own and how would I connect to it from a rails container and also from outside. I'm a complete newbie to Docker and am busy finding my feet.

Any assistance will be very, very much appreciated!
mikeday
You can create a Docker image for Prince by starting with your Linux distribution of choice and the installing Prince on it. Here is an example for CentOS:
FROM centos:7

# Or copy the RPM from the current directory instead of downloading it:
# WORKDIR /app
# ADD . /app
# RUN yum -y install /app/prince-12.4-1.centos7.x86_64.rpm

RUN yum -y update \
 && yum -y install https://www.princexml.com/download/prince-12.4-1.centos7.x86_64.rpm \
 && yum -y install liberation-sans-fonts liberation-serif-fonts liberation-mono-fonts liberation-narrow-fonts \
 && yum clean all

ENTRYPOINT ["prince"]

You could then run Prince as an application within the image, I assume? :)
michaelperrin
I created a Docker image that is similar to the one @mikeday proposed, but based on Alpine.

It is available here: https://hub.docker.com/r/michaelperrin/prince (code is here: https://github.com/michaelperrin/docker-prince).

It's quite convenient to use Prince in a Docker image 🙂
nsnsolutions
Mike, We are using a nodejs wrapper around princeXML any running it from the official node-carbon docker image based on alpine. We ran into a runtime error after our latest build. Apparently the official node-carbon docker image updated to alpine 3.9. We are running a pre-release version at the moment (prince-20171214-alpine3.6-x86_64.tar.gz)

I have been able to fix the majority of the dependencies save one. alpine3.7 ran on openssl but 3.8 switched to ressl. As such, i noticed that prince is looking specifically for libcrypto.so.41 rather then the generic libcrypto.so

2 questions for you:
1. Is it possible to get a alpine 3.9 build for prince 12.5
2. do you have a recommendation to avoid this sort of resource dependency moving forward?

I am prepared to build our own carbon image on 3.8 but i wanted to know if you have any suggestions before i started down this path.

thank you
mikeday
We have an Alpine 3.9 package for Prince 12.5 available now, please give it a try and let me know if you experience any issues with it.
nsnsolutions
I will, thank you. We did end up creating an alpine container with the version of node we needed. It seemed the appropriate thing to do as to not get surprised by an upstream change in the future if anyone else is in the same boat, here is my docker file - i updated it to 3.9 as suggested.

FROM alpine:3.9

RUN apk update && \
    apk upgrade && \
    apk --no-cache add nodejs=10.14.2-r0 && \
    apk --no-cache add npm=10.14.2-r0 && \
    apk --no-cache add libxml2 pixman tiff giflib libpng lcms2 libjpeg libcurl fontconfig freetype libgomp && \
    apk --no-cache add libressl-dev && \
    apk --no-cache add ttf-dejavu

ADD https://www.princexml.com/download/prince-12.5-alpine3.9-x86_64.tar.gz /opt/
RUN tar xzf /opt/prince-*-alpine3.*-x86_64.tar.gz -C /opt/ && \
    /opt/prince-*-alpine3.*-x86_64/install.sh

ADD license.dat /usr/local/lib/prince/license/license.dat

CMD [ "node" ]


Note: your license file is added on the second to last line. you might need to change that to point to the appropriate location.

Edited by nsnsolutions

wangp
Note that Alpine 3.9 switched from LibreSSL to OpenSSL so you don't need the libressl package (for Prince).
mikeday
We have made Docker images available for Prince here:

https://hub.docker.com/r/yeslogic/prince

Which can be used as described in the documentation:

https://www.princexml.com/doc/server-integration/#prince-docker-image
ChristophS
Sorry if this is a stupid question, as I am new to Docker.

We are evaluating Prince for use inside a Spring Boot Java Webservice, and would want to keep Prince running with the --control option (using Java wrapper's PrinceControl class).
Given the way that works with stdin and stdout: Is that possible with Prince and our Java app in separate Docker containers (as our company policies favor, IIUC) or do we have to put them in a single one?
Thanks.
ChristophS
The answer to my question is: Accessing prince --control in a (Linux in Windows) Docker container from a native Windows Java process works. So I assume it should also work from Docker to Docker.

The exePath parameter which we pass to the PrinceControl constructor is "…/prince.cmd", and that script contains:
@echo off
docker run --interactive --attach stdin --attach stdout --attach stderr prince prince --control
mikeday
Yes this might work, although it may be easier to just run Prince from within the same Docker container as the Java process, since it will only live as long as the Java process.
ChristophS
Yes, that makes sense. We'll consider that. Thanks.
ChristophS
My assumption above that I could call the docker run … prince --control from inside Java in Docker as I already did from Java in host was wrong. Instead, it would require Docker-in-Docker or mounting the Docker socket, both of which does not sound very compelling (D-in-D, socket).

So instead, I mounted (docker run --volume) only an empty directory in both containers, where the Java container creates named pipes (via a bash script whose path is passed to the PrinceControl constructor). In the Prince container, inotifywait watches the mounted directory and calls a script which executes Prince reading from / writing to the named pipes.
To my surprise, I did not notice any perfomance penalty. But since noone told me any benefits of smaller containers either, I'll vote for the simpler single container solution.