У меня есть это Dockerfile
для моего приложения:
FROM php:8.0.5-fpm-alpine
WORKDIR /var/www
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN apk update && apk add \
build-base \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libzip-dev \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install Redis Extension
RUN apk add autoconf && pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis && apk del autoconf
# Copy config
COPY ./config/php/local.ini /usr/local/etc/php/conf.d/local.ini
RUN addgroup -g 1000 -S www && \
adduser -u 1000 -S www -G www
USER www
COPY --chown=www:www . /var/www
RUN ["chmod", "+x", "./start_script.sh"]
EXPOSE 9000
CMD ./start_script.sh
Когда я запустил docker-compose up
, он показал мне эту ошибку:
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20200930
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable multibyte string support... yes, shared
checking whether to enable multibyte regex support (requires oniguruma)... yes
checking for oniguruma... no
configure: error: Package requirements (oniguruma) were not met:
Package 'oniguruma', required by 'virtual:world', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables ONIG_CFLAGS
and ONIG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
ERROR: Service 'app' failed to build: The command '/bin/sh -c docker-php-ext-install pdo_mysql mbstring zip exif pcntl' returned a non-zero code: 1
Я пытаюсь выяснить, как это исправить, и я думаю, что это как-то связано с расширением mbstring
PHP, и это расширение mbstring
требуется в Laravel. Поэтому после дальнейших исследований я попытался добавить apk add libonig-dev
, но затем он показывает мне эту новую ошибку:
---> Running in 5cb4450da35b
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.13/community/x86_64/APKINDEX.tar.gz
v3.13.10-66-geb1876c618 [https://dl-cdn.alpinelinux.org/alpine/v3.13/main]
v3.13.10-63-g29cc5622fc [https://dl-cdn.alpinelinux.org/alpine/v3.13/community]
OK: 13914 distinct packages available
ERROR: unable to select packages:
libonig-dev (no such package):
required by: world[libonig-dev]
ERROR: Service 'app' failed to build: The command '/bin/sh -c apk update && apk add build-base libonig-dev freetype-dev libjpeg-turbo-dev libpng-dev libzip-dev zip jpegoptim optipng pngquant gifsicle vim unzip git curl' returned a non-zero code: 1
Я действительно застрял здесь, и я не очень знаком с докером.
🤔 А знаете ли вы, что...
Laravel обладает большим сообществом разработчиков и множеством пакетов.
Вы можете определить свой CMD в файле докеров, как показано ниже. Надеюсь, вы решите свою проблему...!!!
CMD "./start_script.sh"
или же
CMD ["bash", "start_script.sh"]
Вы должны установить пакет oniguruma-dev, прежде чем расширения php, а также параметры конфигурации для gd не будут поддерживаться. Dockerfile должен выглядеть так:
FROM php:8.0.5-fpm-alpine
WORKDIR /var/www
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN apk update && apk add \
build-base \
freetype-dev \
libjpeg-turbo-dev \
libpng-dev \
libzip-dev \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
oniguruma-dev \
curl
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
#RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-configure gd
RUN docker-php-ext-install gd
# Install Redis Extension
RUN apk add autoconf && pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis && apk del autoconf
# Copy config
COPY ./config/php/local.ini /usr/local/etc/php/conf.d/local.ini
RUN addgroup -g 1000 -S www && \
adduser -u 1000 -S www -G www
USER www
COPY --chown=www:www . /var/www
RUN ["chmod", "+x", "./start_script.sh"]
EXPOSE 9000
CMD ./start_script.sh