0

That's my dockerfile

FROM php:7.4-fpm

# Install GD
RUN apt update \
    && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
    && docker-php-ext-configure gd \
    && docker-php-ext-install -j$(nproc) pdo_mysql bcmath exif gd

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www

USER $user

When I try to use conversions from Spatie/Medialibrary I has an error: Call to undefined function Intervention\Image\Gd\imagejpeg()

I tried everything from here and other sites, but it still not helps. A lot of solutions for the LAMP stack, but I have Nginx. I'm a newbie at docker and don't understand what's going wrong. Please help :)

upd.

Last version of dockerfile:

FROM php:7.4-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid

RUN apt-get update && apt-get install -y \
    zlib1g-dev \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev

# Install GD
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
RUN cd /usr/src/php/ext/gd && make
RUN cp /usr/src/php/ext/gd/modules/gd.so /usr/local/lib/php/extensions/no-debug-non-zts-20190902/gd.so
RUN docker-php-ext-install -j$(nproc) gd

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libfontconfig1-dev \
    xclip \
    libjpeg62 \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www

USER $user

I tried a --with-jpeg and --with-freetype, also tried the trick with the folder creation. But still JPEG Support and Freetype support is false.

D3V1L
  • 145
  • 1
  • 1
  • 7
  • 1
    Does this answer your question? [Call to undefined function Intervention\\Image\\Gd\\imagecreatefromjpeg() - laravel](https://stackoverflow.com/questions/51421952/call-to-undefined-function-intervention-image-gd-imagecreatefromjpeg-lara) – Ivan Barayev Sep 09 '21 at 14:40
  • @IvanBarayev it not helps, but it's a step forward, thanks. My JPEG support in gd_info() is disabled. But after I added the same code to dockerfile it's still disabled. – D3V1L Sep 09 '21 at 15:02

1 Answers1

0

Your docker container is missing the php-gd Extension.

This is how we install it in our dockerfile:

RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
  && docker-php-ext-install -j$(nproc) gd \

docker-php-ext-install is a script in the official Docker-Container: https://hub.docker.com/_/php

So in your file you could do this:

RUN apt-get update && apt-get install -y \
git \
curl \
libfontconfig1-dev \
xclip \
libjpeg62 \
libonig-dev \
libxml2-dev \
zip \
unzip \
&& docker-php-ext-configure gd \
&& docker-php-ext-install -j$(nproc) gd
Fels
  • 1,214
  • 2
  • 13
  • 27