Upgrading Nextcloud Docker from 25 to 26

Published

# Contents

I have been running Nextcloud for personal use for a while. A while ago, I encountered a issue when attempting to upgrade, and I have been ignoring keeping it up to date since. As it turns out, the fix was really simple.

# The issue

I am building my own image, based on the nextcloud image. Based on the recommendations. The error I was getting, and my dockerfile, can be seen below.

Can't start Nextcloud because the version of the data (
Warning: PHP Startup: Unable to load dynamic library 'imap.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20220829/imap.so (libc-client.so.2007e: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20220829/imap.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20220829/imap.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
26.0.13.1) is higher than the docker image version (
Warning: PHP Startup: Unable to load dynamic library 'imap.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20220829/imap.so (libc-client.so.2007e: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20220829/imap.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20220829/imap.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
27.0.13.2) and downgrading is not supported. Are you sure you have pulled the newest image version?
nextcloud_app exited with code 1
FROM nextcloud:26.0.13-apache

RUN apt-get update && apt-get install -y procps smbclient && rm -rf /var/lib/apt/lists/*

RUN set -ex; \
    \
    apt-get update; \
    apt-get install -y --no-install-recommends \
        ffmpeg \
        libmagickcore-6.q16-6-extra \
        procps \
        smbclient \
        supervisor \
       libreoffice \
    ; \
    rm -rf /var/lib/apt/lists/*

RUN set -ex; \
    \
    savedAptMark="$(apt-mark showmanual)"; \
    \
    apt-get update; \
    apt-get install -y --no-install-recommends \
        libbz2-dev \
        libc-client-dev \
        libkrb5-dev \
        libsmbclient-dev \
    ; \
    \
    docker-php-ext-configure imap --with-kerberos --with-imap-ssl; \
    docker-php-ext-install \
        bz2 \
        imap \
    ; \
    pecl install smbclient; \
    docker-php-ext-enable smbclient; \
    \
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
    apt-mark auto '.*' > /dev/null; \
    apt-mark manual $savedAptMark; \
    ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
        | awk '/=>/ { print $3 }' \
        | sort -u \
        | xargs -r dpkg-query -S \
        | cut -d: -f1 \
        | sort -u \
        | xargs -rt apt-mark manual; \
    \
    apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
    rm -rf /var/lib/apt/lists/*

# Add preview generation cronjob
# RUN echo '*/10 * * * * php /var/www/nextcloud/occ preview:pre-generate' >> /var/spool/cron/crontabs/www-data

ENV NEXTCLOUD_UPDATE=1

RUN mkdir /var/log/supervisord
RUN mkdir /run/supervisord

COPY supervisord.conf /

CMD ["/usr/bin/supervisord", "-c", "/supervisord.conf"]

# Solution

To solve the issue, I simply needed to replace the line doing awk stuff, as was done in this commit on the official GitHub.

-        | awk '/=>/ { print $3 }' \
+        | awk '/=>/ { so = $(NF-1); if (index(so,"/usr/local/") == 1) { next }; gsub("^/(usr/)?","",so); print so }' \

After this, the container started as it should