3

I have the following error on my docker machine/instance:

Class 'ZipArchive' not found

Here is my Dockerfile:

FROM php:7.2-alpine

RUN docker-php-ext-install sockets pdo_mysql

RUN docker-php-ext-install -j$(nproc) \
    zip

ADD consumer /opt/craft/app/
ADD app.tar.gz /opt/craft/app

CMD /opt/craft/app/consumer

When I sh in to the container via docker-run, I can do php -m:

[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sockets
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

zip is not there. Is it supposed to be there? I have also tried doing:

/opt/craft/app # apk add zip
OK: 17 MiB in 29 packages
/opt/craft/app # php -m

But zip still isn't available and I still get the same output error ziparchive not found.

I'm quite new to docker and installing php modules by myself.

How do I get ZipArchive class installed? (Ideally through dockerfile).

mikelovelyuk
  • 4,042
  • 9
  • 49
  • 95

2 Answers2

3

Actually when I faced Laravel excel problem on php-fpm 7.4 on docker, I find your question. And this answer

RUN apk update \
    && apk upgrade \
    && apk add zlib-dev \
    && docker-php-ext-configure zip --with-zlib-dir=/usr \
    && docker-php-ext-install zip 

don't working forme

I think this Dockerfile works fine for you

FROM php:7.4-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

RUN apt-get update && \
     apt-get install -y \
         libzip-dev \
         && docker-php-ext-install zip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www

USER $user
2

try replace

RUN docker-php-ext-install -j$(nproc) \
    zip

with

RUN apk update \
    && apk upgrade \
    && apk add zlib-dev \
    && docker-php-ext-configure zip --with-zlib-dir=/usr \
    && docker-php-ext-install zip

in Dockerfile

I tried it and it worked.

Daniel1147
  • 151
  • 2
  • 5