Skip to content
Advertisement

Dockerfile: error: ‘docker-php-ext-install’ does not exist and extension does not exist

I’m trying to install some PHP extensions when building a php-apache image. Here’s the ./php/Dockerfile:

FROM php:8.0-apache
RUN docker-php-ext-install bcmath && docker-php-ext-enable bcmath 
        docker-php-ext-install calendar && docker-php-ext-enable calendar 
        docker-php-ext-install gd && docker-php-ext-enable gd 
        docker-php-ext-install mcrypt && docker-php-ext-enable mcrypt 
        docker-php-ext-install pdo_mysql && docker-php-ext-enable pdo_mysql 
        docker-php-ext-install mysqli && docker-php-ext-enable mysqli 
        docker-php-ext-install soap && docker-php-ext-enable soap 
        docker-php-ext-install sockets && docker-php-ext-enable sockets 
        docker-php-ext-install exif && docker-php-ext-enable exif 
        docker-php-ext-install wddx && docker-php-ext-enable wddx 
        docker-php-ext-install wmlrpc && docker-php-ext-enable wmlrpc 
        docker-php-ext-install zip && docker-php-ext-enable zip
RUN apt-get update && apt-get upgrade -y

And here’s the docker-compose.yml:

version: '3.8'
services:
  php-apache-environment:
    container_name: php-apache
    build:
      context: ./php
      dockerfile: Dockerfile
    depends_on:
      - db
    volumes:
      - ./php/src:/var/www/html/
    ports:
      - 80:80
  db:
    container_name: db
    image: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD
      MYSQL_DATABASE: MYSQL_DATABASE
      MYSQL_USER: MYSQL_USER
      MYSQL_PASSWORD: MYSQL_PASSWORD
    ports:
      - "9906:3306"

And when I run docker-compose up -d, this is the error given to me:

error: 'docker-php-ext-install' does not exist

usage: /usr/local/bin/docker-php-ext-enable [options] module-name [module-name ...]
   ie: /usr/local/bin/docker-php-ext-enable gd mysqli
       /usr/local/bin/docker-php-ext-enable pdo pdo_mysql
       /usr/local/bin/docker-php-ext-enable --ini-name 0-apc.ini apcu apc

Possible values for module-name:
bcmath.so opcache.so sodium.so

Some of the above modules are already compiled into PHP; please check
the output of "php -i" to see which modules are already loaded.
The command '/bin/sh -c docker-php-ext-install bcmath && docker-php-ext-enable bcmath   docker-php-ext-install calendar && docker-php-ext-enable calendar      docker-php-ext-install gd && docker-php-ext-enable gd    docker-php-ext-install mcrypt && docker-php-ext-enable mcrypt   docker-php-ext-install pdo_mysql && docker-php-ext-enable pdo_mysql     docker-php-ext-install mysqli && docker-php-ext-enable mysqli   docker-php-ext-install soap && docker-php-ext-enable soap      docker-php-ext-install sockets && docker-php-ext-enable sockets  docker-php-ext-install exif && docker-php-ext-enable exif       docker-php-ext-install wddx && docker-php-ext-enable wddx       docker-php-ext-install wmlrpc && docker-php-ext-enable wmlrpc   docker-php-ext-install zip && docker-php-ext-enable zip' returned a non-zero code: 1
ERROR: Service 'php-apache-environment' failed to build : Build failed

What is wrong in here?

I tried to use all absolute paths like this:

RUN /usr/local/bin/docker-php-ext-install calendar && /usr/local/bin/docker-php-ext-enable calendar 

But then it gives me errors like these:

error: 'calendar' does not exist
error: 'gd' does not exist
error: 'mcrypt' does not exist

Not sure what I’m doing wrong here?

Advertisement

Answer

You are missing && at the end of each line of the long RUN command in the Dockerfile, before .

FROM php:8.0-apache
RUN docker-php-ext-install bcmath && docker-php-ext-enable bcmath && 
        docker-php-ext-install calendar && docker-php-ext-enable calendar && 
        docker-php-ext-install gd && docker-php-ext-enable gd && 
        docker-php-ext-install mcrypt && docker-php-ext-enable mcrypt && 
        docker-php-ext-install pdo_mysql && docker-php-ext-enable pdo_mysql && 
        docker-php-ext-install mysqli && docker-php-ext-enable mysqli && 
        docker-php-ext-install soap && docker-php-ext-enable soap && 
        docker-php-ext-install sockets && docker-php-ext-enable sockets && 
        docker-php-ext-install exif && docker-php-ext-enable exif && 
        docker-php-ext-install wddx && docker-php-ext-enable wddx && 
        docker-php-ext-install wmlrpc && docker-php-ext-enable wmlrpc && 
        docker-php-ext-install zip && docker-php-ext-enable zip
RUN apt-get update && apt-get upgrade -y

Also, extensions should be enabled by default, there is no need to run docker-php-ext-enable, at least with the PHP-FPM images.

One more thing, even with these modifications, your build will likely fail because of missing dependencies and/or unknown extensions (if some are already in the base image).

For instance, gd will need zlib, so you must install these dependencies before installing the extensions (apt update && apt install -y ...).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement