ERROR: unsatisfiable constraints - on php:7-fpm-alpine

ERROR: unsatisfiable constraints - on php:7-fpm-alpine

我正在考虑在 fpm-alpine 容器上设置 laravel。 运行 陷入困境,下面的 Dockerfile 产生了一些错误...

FROM php:7-fpm-alpine

# install extensions needed for Laravel
RUN apk --update add \
  php7-mysqli \
  php7-mcrypt \
  php7-mbstring \
  rm /var/cache/apk/*

产生的错误是:

Building fpm
Step 1 : FROM php:7-fpm-alpine
 ---> 9e6811cb8bac
Step 2 : RUN apk --update add   php7-mysqli   php7-mcrypt   php7-mbstring   rm /var/cache/apk/*
 ---> Running in 87364957eb57
fetch http://dl-cdn.alpinelinux.org/alpine/v3.3/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.3/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  /var/cache/apk/* (missing):
    required by: world[/var/cache/apk/*]
  php7-mbstring (missing):
    required by: world[php7-mbstring]
  php7-mcrypt (missing):
    required by: world[php7-mcrypt]
  php7-mysqli (missing):
    required by: world[php7-mysqli]
  rm (missing):
    required by: world[rm]
ERROR: Service 'fpm' failed to build: The command '/bin/sh -c apk --update add   php7-mysqli   php7-mcrypt   php7-mbstring   rm /var/cache/apk/*' returned a non-zero code: 5

我可以搜索这些包名和find them on the alpine linux web site。关于如何解决这个问题的任何想法?好像它没有更新 apt 缓存...但是添加了一个 LS 我可以在那里看到内容:

Building fpm
Step 1 : FROM php:7-fpm-alpine
 ---> 9e6811cb8bac
Step 2 : RUN apk update
 ---> Using cache
 ---> 9ef09f3aa2a2
Step 3 : RUN ls /var/cache/apk
 ---> Running in e126a083a306
APKINDEX.5a59b88b.tar.gz
APKINDEX.7c1f02d6.tar.gz

有什么办法可以解决这个问题吗?

我没有使用 docker-php-ext-install,这是在容器内添加工作时所必需的...

FROM php:7-fpm-alpine

# install extensions needed for Laravel
RUN apk update \
    && apk add libmcrypt-dev \
    && docker-php-ext-install mcrypt mysqli pdo_mysql \
    && rm /var/cache/apk/*

基本 Docker 图像可能引用了不正确的存储库。

将正确的存储库传递给 apk add 命令,如下所示:

RUN apk add --update \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/main \
--repository http://dl-cdn.alpinelinux.org/alpine/edge/community \
php7-mysqli php7-mcrypt php7-mbstring

我遇到了同样的错误,并尝试了这里的解决方案,发现 apk update 很关键。

我遇到了同样的错误。通过从名称中删除包版本来解决它:

https://github.com/docker-library/php/issues/225#issuecomment-220339154