0

I am trying to use libreoffice in my Django app, to convert a docx file to pdf using python subprocess.

I have included libreoffice in my dockerfile:

Dockerfile:

FROM python:3.8-alpine

ENV PYTHONUNBUFFERED 1

COPY ./requirements.txt /requirements.txt
COPY ./behavioursolutiondjango /behavioursolutiondjango
COPY ./scripts /scripts

WORKDIR /behavioursolutiondjango
EXPOSE 8000

RUN python -m venv /py && \
    /py/bin/pip install --upgrade pip && \
    apk add --update python3-dev \
                          xmlsec xmlsec-dev \
                          gcc \
                          libc-dev \
                          libreoffice \
                          libffi-dev && \
    apk add --update --no-cache postgresql-client && \
    apk add --update --no-cache --virtual .tmp-deps \
        build-base postgresql-dev musl-dev linux-headers && \
    /py/bin/pip install -r /requirements.txt && \
    apk del .tmp-deps && \
    adduser --disabled-password --no-create-home app && \
    mkdir -p /vol/web/static && \
    mkdir -p /vol/web/media && \
    chown -R app:app /vol && \
    chmod -R 755 /vol && \
    chmod -R +x /scripts

ENV PATH="/scripts:/py/bin:$PATH"

USER app

CMD ["run.sh"]

And have the following running to do the conversion:

subprocess.call(["soffice", "--headless", "--convert-to", "pdf", new_cert.cert.path])

But I am running into the following error:

LibreOffice 7.2 - Fatal Error: The application cannot be started. 
User installation could not be completed. 

I have spent hours on this and cannot figure out what im missing.

I would be more than happy to use something other than Libreoffice, but cannot find something that will work, other than libreoffice.

  • Seems like similar question to a recently asked question... did you try this solution? https://stackoverflow.com/questions/72434000/running-libreoffice-converter-on-docker – H3coder Jun 04 '22 at 12:38
  • There doesn’t seem to be a solution shown on that post - the link shows how to install it on windows, which doesn’t help. – Bailey Davis Jun 04 '22 at 22:13
  • This one contained a few more things to try: [Python sub-process in Docker](https://stackoverflow.com/questions/49439955/subprocess-not-working-in-docker-container) – H3coder Jun 05 '22 at 01:28

0 Answers0