How to install and run wkhtmltopdf Docker image
Asked Answered
M

3

18

I want to install and run wkhtmltopdf from Dockerfile of Spring-Boot application when I will build and run the Spring-boot application. I have written the below given scripts in Dockerfile to install wkhtmltopdf.

FROM debian:jessie

RUN apt-get update \
    && apt-get install -y \
        curl \
        libxrender1 \
        libfontconfig \
        libxtst6 \
        xz-utils

RUN curl "https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz" -L -o "wkhtmltopdf.tar.xz"
RUN tar Jxvf wkhtmltopdf.tar.xz
RUN mv wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf

ENTRYPOINT ["wkhtmltopdf"]

The above scripts created a docker images, but how to run those images to test wkhtmltopdf is working or not? Or Any other approach we have to install & run wkhtmltopdf from Dockerfile?

Mailbox answered 26/6, 2020 at 6:52 Comment(0)
M
12

Another simple answer:

# Create image based on the official openjdk 8-jre-alpine image from the dockerhub
FROM openjdk:8-jre-alpine

# Install wkhtmltopdf
RUN apk add --no-cache wkhtmltopdf

ENTRYPOINT ["wkhtmltopdf"]
Mailbox answered 5/7, 2020 at 5:25 Comment(2)
This solved it for me! It installs wkhtmltopdf to /usr/local/bin/wkhtmltopdf. You can check if it's correctly installed by sh-ing into your Docker container and running wkhtmltopdf --version.Noach
I would like to try this answer but I'm afraid I don't know exactly how to implement it. do you suggest to run wkhtmltopdf in it's own container (and access it somehow via the docker network from app container) or is this meant to be installed in the same container where the app is running? thxRegardful
S
16

Perhaps this solution will help. Wkhtmltopdf will be install to /usr/bin/wkhtmltopdf

RUN apt-get update \
    && apt-get install -y \
    ...
    wkhtmltopdf \
    ...
Supper answered 12/3, 2021 at 15:7 Comment(0)
M
12

Another simple answer:

# Create image based on the official openjdk 8-jre-alpine image from the dockerhub
FROM openjdk:8-jre-alpine

# Install wkhtmltopdf
RUN apk add --no-cache wkhtmltopdf

ENTRYPOINT ["wkhtmltopdf"]
Mailbox answered 5/7, 2020 at 5:25 Comment(2)
This solved it for me! It installs wkhtmltopdf to /usr/local/bin/wkhtmltopdf. You can check if it's correctly installed by sh-ing into your Docker container and running wkhtmltopdf --version.Noach
I would like to try this answer but I'm afraid I don't know exactly how to implement it. do you suggest to run wkhtmltopdf in it's own container (and access it somehow via the docker network from app container) or is this meant to be installed in the same container where the app is running? thxRegardful
M
6
# (Multi stage Docker can be considered. The appropriate Gradle cache use remains to be solved)

# Create image based on the official openjdk 11-jre-slim image from the dockerhub
FROM debian:jessie

ENV DIR=/usr/local/bin/

# Change directory so that our commands run inside this new directory
WORKDIR $DIR

ENV WKHTML_VERSION 0.12.4

# Builds the wkhtmltopdf download URL based on version number above
ENV DOWNLOAD_URL "https://downloads.wkhtmltopdf.org/0.12/${WKHTML_VERSION}/wkhtmltox-${WKHTML_VERSION}_linux-generic-amd64.tar.xz" -L -o "wkhtmltopdf.tar.xz"

# Install dependencies
RUN apt-get update && apt-get install -y \
    curl libxrender1 libfontconfig libxtst6 xz-utils

# Download and extract wkhtmltopdf
RUN curl $DOWNLOAD_URL
RUN tar Jxvf wkhtmltopdf.tar.xz
RUN cp wkhtmltox/bin/wkhtmltopdf $DIR

ENTRYPOINT ["wkhtmltopdf"]
Mailbox answered 5/7, 2020 at 5:21 Comment(1)
For me, https://downloads.wkhtmltopdf.org doesn't work. Had to change it to github link https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz . Also, for my setup, I needed to install libssl1.0-dev as well.Chapel

© 2022 - 2024 — McMap. All rights reserved.