I have this Dockerfile
for my app:
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
When I ran docker-compose up
its showing me this error:
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
I try to research how to fix this and I think this has something to do with the mbstring
PHP extension and this mbstring
extension is required in Laravel. So upon further research I tried to add apk add libonig-dev
, but then it shows me this new error:
---> 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
I'm really stuck here and I'm not really familiar with docker.
CodePudding user response:
You can define your CMD in the dockerfile like below, Hope you will resolve your issue...!!!
CMD "./start_script.sh"
or
CMD ["bash", "start_script.sh"]
CodePudding user response:
You must install the oniguruma-dev package before the php extensions and also the configuration options for gd are not supported. The Dockerfile should look like this:
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