dockerimagemagickdockerfile

Change ImageMagick policy on a Dockerfile


There seems to have been a change recently on ImageMagick which breaks conversion from pdf to png. My investigation let me to the policy.xml file and this line:

<policy domain="coder" rights="none" pattern="PDF" />

which needs to be changed to this

<policy domain="coder" rights="read|write" pattern="PDF" />

(Note: I didn't have this problem before).

I am able to change that on my personal machine but now I need to change it on a docker container configured through a Dockerfile. How can I do that?

I have tried something using environment variables without success. You can see my dockerfile here:

https://github.com/VivianePons/public-notebooks

Thank you for your help


Solution

  • Runtime bind mount

    At runtime (docker run), use a bind mounted volume to overwrite the policy.xml inside the container.

    A good, straightforward example of doing this can be found in the How to use this image section of the official Nginx image on Docker Hub.

    docker run --name some-nginx -v /some/content:/usr/share/nginx/html -d nginx

    Here, the -v flag is your bind mount. -v /some/content:/usr/share/nginx/html says "replace /usr/share/nginx/html in the container with the contents of /some/content on my host. The end result for the user -- if /some/content has an index.html or other default home page as determined in the nginx.conf of the container, Nginx will require no configuration changes because the default Nginx configuration is already looking for index.html at that file system location.

    NOTE: Bind mounting isn't additive. The directory on the image will be entirely replaced by whats being mounted.

    Dockerfile COPY

    Or at build time (docker build) use COPY in your Dockerfile to bake your updated policy.xml right into the container, no bind mounting required.

    COPY ./path/to/policy.xml /path/in/docker/image/policy.xml