0

Content of my Dockerfile:

FROM php:8.1-apache

WORKDIR /var/www/html/

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug \
    && a2enmod rewrite \
    && docker-php-ext-install zip

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY composer.json composer.json
COPY composer.lock composer.lock

RUN groupadd -r user && useradd -r -g user user
USER user
RUN composer install --no-dev

COPY . .

EXPOSE 80

The composer installation fails at the point where it's telling me that the libzip package is needed. I can however not find that package, no matter if via pecl, via apt-get; as most of the forum posts refer to. How can I Install libzip to finally get things running?

A few notes on my Dockerfile lines; feel free to correct me if I'm wrong in the setup; it's the first time I'm doing this:

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY composer.json composer.json
COPY composer.lock composer.lock

As I understood it, the official docs tell you to use this multi-stage approach to get composer running in your PHP Docker container in an optimal way. If I understood it correctly, doing it in this way allows you to share your image without your colleagues needing to install composer / download the packages locally; everything will then be done within the container. Which is exactly what I'm looking for.

RUN groupadd -r user && useradd -r -g user user
USER user
RUN composer install --no-dev

I first tried to simply run the last line composer install --no-dev, which actually won't work, as the container won't let you execute root commands; used by default by composer. Hence the reason for this workaround (changing the user is also what the official docs recommend; according to the link above).

&& docker-php-ext-install zip

When finally able to run the composer install command within the container, it told me that the zip extension is needed; which is why I've added the docker-php-ext-install zip command. Now I'm stuck due to the initially mentioned libzip issue.

If you see a better way to setup composer; I'm happy to hear about a better way.

1 Answer 1

1

docker-php-ext-enable is looking for the libzip header files. What you need is the package libzip-dev.

RUN pecl install xdebug \
    && apt update \
    && apt install libzip-dev -y \
    && docker-php-ext-enable xdebug \
    && a2enmod rewrite \
    && docker-php-ext-install zip \
    && rm -rf /var/lib/apt/lists/*
2
  • Great, cheers, that works! The only problem now is that there's no vendor folder in my container root??
    – DevelJoe
    Nov 11, 2022 at 10:56
  • 1
    That would be a new question. The relevant output from the build would probably be helpful. Nov 11, 2022 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.