I always used GD to manipulate webp normally in my local environment, but when attempting to test my scripts in docker environment, i get "Webp format is not supported by PHP installation." error. I am using latest php version as in showed in my dockerfile below:
FROM php:8-fpm
# 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 \
pngquant
# 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
# php.ini
COPY ./docker-compose/php/php.ini /usr/local/etc/php/
What i am missing?
You need to install libwebp-dev and configure gd lib to support it:
RUN apt-get update && ... \
apt-get install -y libwebp-dev && \
docker-php-ext-configure gd --with-webp;
The the examples here : https://github.com/docker-library/docs/tree/master/php#how-to-install-more-php-extensions
Related
I am trying to dockerize a PHP laravel app. I am using a PHP and a composer image to achieve this. However, when I run composer install, I get all my packages installed but then run into this error:
/app/vendor does not exist and could not be created.
I want composer to create the /vendor directory! Could this be a permission issue?
Here is my Dockerfile:
FROM php:7.4.3-cli
# 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
COPY --from=composer:2.4.4 /usr/bin/composer /usr/local/bin/composer
# Set working directory
WORKDIR /app
COPY . .
# Add a new user "john" with user id 8877
RUN useradd -u 8877 john
# Change to non-root privilege
USER john
RUN composer install
I created a user with an arbitrary ID since it's a bad practice to run composer install as root security-wise.
I was able to solve the problem by making some changes to my Dockerfile:
FROM php:7.4.3-cli
# 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
COPY --from=composer:2.4.4 /usr/bin/composer /usr/local/bin/composer
# Add a new user "john" with user id 8877
RUN useradd -u 8877 john
# Set working directory
WORKDIR /app
COPY . .
RUN chmod -R 775 /app
RUN chown -R john:john /app
# Change to non-root privilege
USER john
RUN composer install --no-scripts --no-plugins
I'm still learning docker, and i'm trying to Dockerize a laravel project.
I'm trying to execute laravel composer in docker, however git does not work:
[RuntimeException] git was not found in your PATH, skipping source download
Git works normal in my local machine.
My Docker file:
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql sockets
RUN curl -sS https://getcomposer.org/installer​ | php -- \
--install-dir=/usr/local/bin --filename=composer~
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
WORKDIR /app
COPY . .
RUN composer install
I've tried to install git using dockerfile:
FROM alpine
RUN apk add --no-cache git
CMD ["git","--version"]
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git
but docker build dont work:
=> ERROR [stage-0 8/8] RUN apt-get update && apt-get upgrade -y && apt-get install -y git
docker-compose.yml:
version: '3.8'
services:
php-apache-environment:
container_name: php-apache.
image: php:7.4-apache
volumes:
- ./:/var/www/html
ports:
- 8001:80
How git works in docker? I have to change my environment variables somehow or can i install git on docker?
Or perhaps both and i doing both wrong?
I believe COPY --from=composer:2.0 /usr/bin/composer /usr/bin/composer is sufficient to install composer in you docker project .
I created a dockerfile for a laravel project before and this is how it looked
FROM php:7.3-apache
# 1. development packages
RUN apt-get update && apt-get install -y \
git \
zip \
curl \
sudo \
unzip \
libzip-dev \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libfreetype6-dev \
g++
# 2. apache configs + document root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers
# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install \
bz2 \
intl \
iconv \
bcmath \
opcache \
calendar \
mbstring \
pdo_mysql \
zip
#upload
RUN echo "file_uploads = On\n" \
"memory_limit = 500M\n" \
"upload_max_filesize = 500M\n" \
"post_max_size = 500M\n" \
"max_execution_time = 600\n" \
> /usr/local/etc/php/conf.d/uploads.ini
# 5. composer
COPY --from=composer:2.0 /usr/bin/composer /usr/bin/composer
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.
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
Hi i am new to docker.
I have cloned my laravel code from
https://github.com/laravel/laravel/tree/8.x
and followed the steps provided in given below link.
https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose
But still, mbstring is not installed in my project with php 8 version as my laravel project is compatible with a higher version than 7.2 but when i tried mbstring with 7.2 version it was easyly installed. i want to install mbstring with php 8 version.
Given below is my docker file. please have a look at it.
FROM php:8.0.3-fpm-buster
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
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 composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
FROM php:8-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions mbstring pdo_mysql zip exif pcntl gd
#previous code
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
#RUN docker-php-ext-install
#RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
RUN php artisan key:generate
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
Try this..
What follows is more appropriate as a comment, but I have an insufficient reputation to comment.
Adarsh Hiwrale's excellent suggestion mostly worked for me, but I had to rearrange a few lines to avoid a race condition.
That is, the reordered lines are necessary for anyone starting from scratch who is building for the first time because they will not yet have a partial Docker build that can execute RUN php artisan key:generate.
My revision follows with comments indicating what was modified and why.
FROM php:8-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions mbstring pdo_mysql zip exif pcntl gd
#previous code
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
#RUN docker-php-ext-install
#RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# BEGIN MODIFICATIONS to Adarsh Hiwrate's suggested code
# Copy existing application directory contents
# The following line is redundant (predundant?) because of the line which copies the required items with the correct permissions.
# COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# This has to come after the above copy, otherwise the code will not yet be available in the container.
RUN php artisan key:generate
# END MODIFICATIONS to Adarsh Hiwrate's suggested code
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
This question already has answers here:
ADD failed : No such file/Directory while building docker image
(3 answers)
Closed 2 years ago.
I got this error when building docker php image
Step 13/25 : ADD php.ini /usr/local/etc/php/php.ini
ERROR: Service 'phpt3' failed to build: ADD failed: stat
/var/lib/docker/tmp/docker-builder310748204/php.ini: no
such file or directory
Below is the docker file:
FROM php:7.3-fpm
# install the PHP extensions we need
RUN apt-get update \
&& apt-get install -y --no-install-recommends msmtp mailutils vim curl debconf subversion git apt-transport-https apt-utils \
build-essential locales acl mailutils wget nodejs \
gnupg gnupg1 gnupg2 \
zlib1g-dev zlib1g-dev libicu-dev g++ \
sudo
# Install GD
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
# MYSQLI
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
# Install ext-zip
RUN apt-get install -y unzip libzip-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-configure intl
RUN docker-php-ext-install pdo_mysql json calendar intl
ADD php.ini /usr/local/etc/php/php.ini
COPY additionnal.ini /usr/local/etc/php/conf.d/
COPY php-fpm-pool.conf /usr/local/etc/php/pool.d/www.conf
RUN rm -rf /var/lib/apt/lists/* \
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
# set up sendmail config, see http://linux.die.net/man/5/ssmtp.conf for options
RUN echo "hostname=localhost.localdomain" > /etc/msmtp/msmtp.conf
RUN echo "mailhub=maildevt3" >> /etc/msmtp/msmtp.conf
# The above 'maildevt3' is the name you used for the link command
# in your docker-compose file or docker link command.
# Docker automatically adds that name in the hosts file
# of the container you're linking MailDev to.
# Set up php sendmail config
RUN echo "sendmail_path=sendmail -i -t" >> /usr/local/etc/php/conf.d/php-sendmail.ini
# Fully qualified domain name configuration for sendmail on localhost.
# Without this sendmail will not work.
# This must match the value for 'hostname' field that you set in ssmtp.conf.
RUN echo "localhost localhost.localdomain" >> /etc/hosts
WORKDIR /var/www/
EXPOSE 9000
CMD ["php-fpm"]
Can anyone help me to overcome this bug.
I'm doing this tutorial
https://passions.miary.dev/2019/08/30/docker-maildev-fr/
It looks like the image installer does not have the rights to write to the installation directory.
-> How to fix:
ADD failed : No such file/Directory while building docker image
If that doesn't work: test if the folder, which is shown in the error exists.
Give enough permissions to the directory with chmod -> https://wiki.ubuntuusers.de/chmod/