php: PECL not working in php:7.4-fpm-alpine up from php:7.3-fpm-alpine due to DNS issue with pecl.php.net
After changing from php:7.3-fpm-alpine to php:7.4-fpm-alpine, the pecl install
command stopped working. The error given in the docker build process is: No releases available for package "pecl.php.net/redis"
for RUN pecl install redis-5.3.2
tl;dr: The problem seems to be with alpine 3.13 and not 3.12, so you can use php:7.4.15-fpm-alpine3.12.
Digging for cause
Many older resources online refer to the Great Firewall of China as the cause as this seems to be a network issue, but I’m not in China or behind any strange network setup. I dig on.
Entering the container, the following things seem problematic and related:
bash-5.1# pecl install redis-5.3.2
No releases available for package "pecl.php.net/redis"
install failed
bash-5.1# pear update-channels
Updating channel "doc.php.net"
Channel "doc.php.net" is up to date
Updating channel "pear.php.net"
Channel "pear.php.net" is up to date
Updating channel "pecl.php.net"
Channel "pecl.php.net" is not responding over http://, failed with message: Connection to `pecl.php.net:80' failed: php_network_getaddresses: getaddrinfo failed: Try again
Trying channel "pecl.php.net" over https:// instead
Cannot retrieve channel.xml for channel "pecl.php.net" (Connection to `ssl://pecl.php.net:443' failed: php_network_getaddresses: getaddrinfo failed: Try again)
bash-5.1#
It makes sense that if pecl.php.net is not reachable then it pecl install
will fail. The cause seems to be related to resolving the hostname:
bash-5.1# nslookup pear.php.net
Server: 192.168.65.1
Address: 192.168.65.1:53
Non-authoritative answer:
pear.php.net canonical name = euk3.php.net
Non-authoritative answer:
pear.php.net canonical name = euk3.php.net
Name: euk3.php.net
Address: 109.203.101.62
bash-5.1# nslookup pecl.php.net
Server: 192.168.65.1
Address: 192.168.65.1:53
Non-authoritative answer:
Name: pecl.php.net
Address: 104.236.228.160
Non-authoritative answer:
*** Can't find pecl.php.net: No answer
bash-5.1#
From here on out I’m not sure what the root cause of this problem is, but I do see a working IP address for pecl.php.net.
Proof of concept
Changing the command in the Dockerfile from:
RUN pecl install redis-5.3.3
to:
RUN echo "104.236.228.160 pecl.php.net" >> /etc/hosts && pecl install redis-5.3.3
solves the problem entirely.
This is not a sustainable fix because if the DNS for this address changes it will stop working.
Workaround
This problem does not occur on the alpine3.12-based image: php:7.4.15-fpm-alpine3.12.
Proposed solution
I suggest to recall the alpine 3.13 based images entirely and use 3.12 instead.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 16 (6 by maintainers)
I’m still running into this issue using php:8.1-fpm-alpine. macOS works fine, however WSL2 fails.
Great find, I just tested with php:7.4.15-fpm-alpine3.12 and that worked as normal. I edited my post above to reflect that the workaround should just be to use that specific image.
Since I don’t know how else this alpine image bug could manifest in a php application I would like to propose that the php alpine 3.13 images be removed or at least the default tags set to the 3.12 version that doesn’t have this issue.
This seems potentially related to whatever is going on in https://github.com/alpinelinux/docker-alpine/issues/149 🤔 😬