如何安装和运行wkhtmltopdf Docker镜像

soat7uwm  于 2023-05-22  发布在  Docker
关注(0)|答案(3)|浏览(354)

我想在构建和运行Spring-boot应用程序时,从Spring-Boot应用程序的Dockerfile安装并运行wkhtmltopdf。我用Dockerfile编写了下面的脚本来安装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"]

上面的脚本创建了一个docker镜像,但是如何运行这些镜像来测试wkhtmltopdf是否工作?或者我们必须从Dockerfile安装并运行wkhtmltopdf的任何其他方法?

cgfeq70w

cgfeq70w1#

另一个简单的答案:

# 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"]
ef1yzkbh

ef1yzkbh2#

也许这个解决方案会有所帮助。Wkhtmltopdf将安装到/usr/bin/wkhtmltopdf

RUN apt-get update \
    && apt-get install -y \
    ...
    wkhtmltopdf \
    ...
cx6n0qe3

cx6n0qe33#

# (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"]

相关问题