Run `docker-php-ext-install` from a container other than php

I have a problem with Docker (docker-compose). I want to install some PHP extensions using docker-compose.yml , but I cannot do this because my .yml has FROM ubuntu and not FROM php . Is there a way I can reach or access docker-php-ext-install ?

Dockerfile

 FROM ubuntu:16.04 RUN apt -yqq update RUN apt -yqq install nginx iputils-ping RUN docker-php-ext-install pdo pdo_mysql mbstring WORKDIR /usr/local/src COPY docker/nginx/dev.conf /etc/nginx/conf.d/dev.conf COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf CMD ["nginx"] 

docker-compose.yml

 version: "2" services: mariadb: image: mariadb environment: - MYSQL_ALLOW_EMPTY_PASSWORD=1 - MYSQL_ROOT_PASSWORD= phpmyadmin: image: phpmyadmin/phpmyadmin ports: - "8080:80" restart: always environment: - PMA_HOST=mariadb links: - mariadb php: image: php:7.1.1-fpm ports: - "9000:9000" volumes: - .:/dogopic links: - mariadb nginx: build: . ports: - "8000:80" volumes: - .:/dogopic links: - php 

Console exit (fragment)

 Step 5/9 : RUN docker-php-ext-install pdo pdo_mysql mbstring ---> Running in 445f8c82883d /bin/sh: 1: docker-php-ext-install: not found 
+15
docker docker-compose dockerfile php-extension
source share
3 answers

New solution

You need to create a new Dockerfile for a specific service, in this case php :

php/Dockerfile

 FROM php:7.1.1-fpm RUN apt -yqq update RUN apt -yqq install libxml2-dev RUN docker-php-ext-install pdo_mysql RUN docker-php-ext-install xml 

And then a link to it in your docker-compose.yml , like this:

 services: // other services php: build: ./php ports: - "9000:9000" volumes: - .:/dogopic links: - mariadb 

Please look at the build parameter - it points to the directory where this new Dockerfile is located.

Old decision

I got around the problem. I realized that I can still run this docker-php-ext-install script using the following command:

 docker-compose exec <your-php-container> docker-php-ext-install pdo pdo_mysql mbstring 

And because of the convenience, I created this simple batch file to simplify the creation of containers with only one command: ./docker.bat

 @ECHO OFF docker-compose build docker-compose exec php docker-php-ext-install pdo pdo_mysql mbstring docker-compose up 
+23
source share

docker-php-ext-install not some native docker functionality. If you carefully read the php docker hub page, you will see that this is just a script that facilitates the installation process:

We provide docker-php-ext-configure , docker-php-ext-install and docker-php-ext-enable helper scripts to simplify the installation of PHP extensions.

If your image is based on ubuntu and not php , you can find docker-php-ext-install , for example, on github .

But since your Dockerfile is FROM ubuntu , I advise you to install php using apt-get :

 FROM ubuntu:16.04 RUN apt -yqq update RUN apt -yqq install nginx iputils-ping RUN apt-get install -y php php-fpm pdo-mysql php-mbstring 

Remember to configure nginx to use php-fpm. To do this, I personally use the start.sh script, which runs php-fpm and nginx in the container:

 php-fpm -D nginx -g "daemon off;" 

And in Dockerfile I run the script. not nginx :

 COPY start.sh /tmp/start.sh CMD ["/tmp/start.sh"] 
+9
source share

I have the same problem. I get a message:

 docker-php-ext-configure: not found 

I have this file in my php container.

I don’t know why this does not work!

0
source share

All Articles