Osama Eshtiaq
Osama Eshtiaq

Reputation: 73

I am having problem installing wkhtmltopdf on my docker container for a Django application?

I am using pdfkit in my django application and it seems to be working fine after I installed wkhtmltopdf on my machine. But when I build a docker image of my application for production and run it locally, it gives me OS Error for docker image. I have tried everything I found on the web but can't seem to install wkhtmltopdf on my docker container. Here's my Docker File for building an image, this gives error while installing the package.

FROM python:3.6.9

RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.1/wkhtmltox-0.12.1_linux-wheezy-amd64.deb
RUN dpkg -i ~/Downloads/wkhtmltox-0.12.1_linux-wheezy-amd64.deb

WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . .

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Here's the error I get in the terminal while building the image enter image description here

Here's the error without wkhtmltopdf in docker enter image description here

Upvotes: 0

Views: 4684

Answers (2)

Cristian Lazo
Cristian Lazo

Reputation: 123

This Dockerfile works with django and the newest version of wkhtmltopdf (0.12.6-1)

# pull official base image
FROM python:3.9-buster

RUN apt-get update \
    && apt-get install -y \
        curl \
        libxrender1 \
        libjpeg62-turbo \
        fontconfig \
        libxtst6 \
        xfonts-75dpi \
        xfonts-base \
        xz-utils
RUN curl "https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_amd64.deb" -L -o "wkhtmltopdf.deb"

RUN dpkg -i wkhtmltopdf.deb

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .

RUN pip install -r requirements.txt

# copy project
COPY . .

EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Upvotes: 0

Osama Eshtiaq
Osama Eshtiaq

Reputation: 73

I figured it out. My DockerFile was missing some code.

FROM python:3.6.9

RUN wget https://s3.amazonaws.com/shopify-managemant-app/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
RUN tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
RUN mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
RUN chmod +x /usr/local/bin/wkhtmltopdf


WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . .

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

Now the image is running just fine

Upvotes: 1

Related Questions