[php] Package 'php-xml' has no installation candidate

$ cat Dockerfile 
FROM php
RUN apt-get update \
    && apt-get -y install php-xml

$ docker build .
[+] Building 7.5s (5/5) FINISHED                                                                        docker:default
 => [internal] load build definition from Dockerfile                                                              0.0s
 => => transferring dockerfile: 101B                                                                              0.0s
 => [internal] load metadata for docker.io/library/php:latest                                                     0.0s
 => [internal] load .dockerignore                                                                                 0.0s
 => => transferring context: 2B                                                                                   0.0s
 => CACHED [1/2] FROM docker.io/library/php:latest                                                                0.0s
 => ERROR [2/2] RUN apt-get update     && apt-get -y install php-xml                                              7.4s
------                                                                                                                 
 > [2/2] RUN apt-get update     && apt-get -y install php-xml:                                                         
0.351 Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]                                                   
0.462 Get:2 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]                                          
0.513 Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]                                
0.567 Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8792 kB]                                        
4.983 Get:5 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [13.5 kB]
4.991 Get:6 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [241 kB]
6.023 Fetched 9301 kB in 6s (1618 kB/s)
6.023 Reading package lists...
6.584 Reading package lists...
7.167 Building dependency tree...
7.316 Reading state information...
7.326 Package php-xml is a virtual package provided by:
7.326   php8.2-xml 8.2.26-1~deb12u1 [Not candidate version]
7.326 
7.330 E: Package 'php-xml' has no installation candidate
------
Dockerfile:2
--------------------
   1 |     FROM php
   2 | >>> RUN apt-get update \
   3 | >>>     && apt-get -y install php-xml
   4 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update     && apt-get -y install php-xml" did not complete successfully: exit code: 100

Package ‘php-xml’ has no installation candidate

Why?

It seems to be a problem with the pckages of the Linux distribution. But the official PHP image is not based on the PHP installed from APT repositories. So you should not install any php module from APT repositories as there is no PHP for that.

The official image description shows how you can install modules. But can’t tell you what php-xml would install so I don’t know what module name you would need.

Where are such instructions?
I tried on https://hub.docker.com/_/php but the Serer doesn’t answer

Exactly on the page you shared. It works now.

There are a lot of examples and I don’t know which one to use.
Let’s pretend that I want to install docker php image, the php-xml extension.
How should I do?

# This is Dockerfile
FROM php:latest
RUN ...

and then?

Did you check the PHP XML doc? Are you sure it’s not already included?

Did you check the docker-php-extension-installer repository?

I only see a tide of links.
If you give me a straight …

You need a PHP extension so read the “How to install more PHP extensions” part. Ofcourse you need to know which extension you want to use. Then you can start searching for ways to install it. The documentation always shows which fucntion requires what extension since the function’s documentations are categorized by the libraries from which you can find extension names. You click the parent pages in the navigation bar and search for the “Introduction” and/or “Installing/configuring” links. .

Actually it couldn’t be straighter as PHP developers should be familiar with the PHP documentation and this is a Docker community forum where users can also have some PHP experiences, but not necessarily actively practicing it.

The page @bluepuma77 shared is the list of XML-related libraries/extensions where you can find “Introduce” and “installing/configuring” links. If you know which function, class you need, you can find which library you need and which extension you need. And finally how it should be installed if it has to be installed at all, since some extensions are available by default.

Now we arrived to the point which indeed requires Docker-related skills or at least a good Linux skills as you need to find out which libraries are required on Linux to build a PHP extension. You can find examples in my repository and if this is what you need, this iss the xml extenions

I don’t know if this is what php-xml was supposed to install or not.

$ curl https://www.php.net/manual/en/refs.xml.php | grep -iF "How to install more PHP extensions" || echo NOT FOUND
NOT FOUND

mmmhhh…???
Where did I say I intend to create any extension?

Very well, thanks.
At least on this point I would say that we are there.

Are you kidding? Check the page, PHP has multiple XML libraries. Check which one you want to use or which one your code requires. Library names have changed over time.

You confused my post with @bluepuma77’s post. I replied to your post about the official image description not the PHP docs…

It is not whether you want or not. The official PHP images contain PHP versions built from source code so extensions are built from source as well. The Docker image just provides scripts that make it easier, and in some cases, the extension is built-in, so you just need to enable it. But if it has to be built, you need to install required libraries which you can remove after a successfull build, unless it is required in runtime as well.

This is what I referred to as required good “Linux skills” as PHP developers might be familiar with the structure of the PHP documentation, but not necessarily the way to recognize which library is required based on error messages, although, in many cases the package name is specifically mentioned.

I confused myself.

The correct link was https://hub.docker.com/_/php (“How to install more PHP extensions”).
Here, however, there is the list of bookstores/extensions PHP: XML Manipulation - Manual

Now I understand!!!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.