[英]Docker build: Extentions not loading via apk: exif, gd, pdo_mysql, pecl-redis. What can I do to fix my dockerfile? From php:7.4-fpm-alpine
I'm using FROM php:7.4-fpm-alpine
as my image and trying to load everything I need with RUN add apk
, everything seems to build correctly, but some things are not actually working when I try to use them.我正在使用
FROM php:7.4-fpm-alpine
作为我的图像并尝试使用RUN add apk
加载我需要的所有内容,一切似乎都正确构建,但是当我尝试使用它们时,有些东西实际上并没有工作。
Searching around I seem to have found workarounds for all of them, but now my dockerfile take a long long time to build.环顾四周,我似乎找到了所有这些方法的解决方法,但现在我的 dockerfile 需要很长时间才能构建。 I'm just learning Docker and on a super slow internet connection, so this is not ideal.
我只是在学习 Docker 并且互联网连接速度超慢,所以这并不理想。
I'm wondering if I am doing something wrong?我想知道我是否做错了什么? Or if I can make my dockerfile more efficient.
或者,如果我能让我的 dockerfile 更有效率。 -- Thanks!
- 谢谢!
My Dockerfile:我的 Dockerfile:
FROM php:7.4-fpm-alpine
RUN apk update \
&& apk add curl php7-curl php7-json php7-tokenizer php7-mbstring php7-exif php7-fileinfo \
php7-bcmath php7-dom php7-session php7-simplexml php7-ctype
#* PDO EXIF The apk is not working!
# RUN apk add php7-exif
RUN docker-php-ext-install exif
#* EXT-GD The apk is not working!
# RUN apk add php7-gd
RUN apk add libpng libpng-dev && docker-php-ext-install gd && apk del libpng-dev
#* PDO MYSQL The apk is not working!
# RUN apk add php7-pdo php7-pdo_mysql
RUN docker-php-ext-install pdo pdo_mysql
#* EXT-REDIS The apk is not working!
# RUN apk php7-pecl-redis
RUN apk add --no-cache pcre-dev $PHPIZE_DEPS \
&& pecl install redis \
&& docker-php-ext-enable redis.so
#* Get permissions right
RUN apk add shadow && usermod -u 1000 www-data && groupmod -g 1000 www-data
The official php Docker Image uses a self compiled version of php which is not compatible with the php included in the Alpine package repository. The official php Docker Image uses a self compiled version of php which is not compatible with the php included in the Alpine package repository. You have two choices to solve this:
你有两种选择来解决这个问题:
docker-php-ext-install
and docker-php-ext-enable
for everything and no apk add php*
ordocker-php-ext-install
和docker-php-ext-enable
并且没有apk add php*
或 A long build time does not necessarily mean your internet connection is to slow.较长的构建时间并不一定意味着您的互联网连接速度很慢。 Compiling
exif
, gd
, pdo_mysql
and redis
takes it time, too.编译
exif
、 gd
、 pdo_mysql
和redis
需要时间。 Check your bandwidth and CPU usage while building the image and then you know for sure where your bottle neck is.在构建映像时检查您的带宽和 CPU 使用率,然后您就可以确定瓶颈在哪里。 To speed things up you can efficiently cache layers by first installing dependencies with apk, then composer, pip, etc. and finally adding your code.
为了加快速度,您可以通过首先使用 apk 安装依赖项,然后是 composer、pip 等,最后添加您的代码来有效地缓存层。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.