Docker& PHP 8 fpm& Laravel设置

发布于 2025-02-12 02:30:53 字数 3311 浏览 0 评论 0原文

我的应用程序有此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时,它向我显示了这个错误:

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添加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

我真的卡在这里,我对Docker并不熟悉。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灰色世界里的红玫瑰 2025-02-19 02:30:53

您必须在PHP扩展之前安装Oniguruma-Dev软件包,并且不支持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

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
苏大泽ㄣ 2025-02-19 02:30:53

您可以在下面的Dockerfile中定义您的CMD,希望您能解决您的问题... !!!

cmd“ ./start_script.sh”

cmd [“ bash”,“ start_script.sh”]

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"]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文