I triedto install gd extension on docker but it doesn't worked,I found some examples many with php-fm, but its not working with the image that I used,this is my dockerfile
:
FROM php:7.4.2-apache
RUN pecl install xdebug && docker-php-ext-enable xdebug && docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable pdo_mysql && pecl install apcu && docker-php-ext-enable apcu \
# not yet in linux: xdebug.remote_host = host.docker.internal \n\
&& echo "\n\
xdebug.mode = debug \n\
xdebug.start_with_request = yes \n\
xdebug.client_port = 9003 \n\
xdebug.client_host = 172.18.0.1 \n\
xdebug.log = "C:\xdebug_log\xdebug.log" \n\
xdebug.idekey = VSCODE \n\
" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN apt-get update \
&& apt-get -y --no-install-recommends install libfontconfig1 libxrender1 libxext6 \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
RUN cd /usr/local/etc/php/conf.d/ && \
echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
RUN docker-php-ext-install opcache && docker-php-ext-enable opcache
UPDATE:
I made some changes , then my dockerfile is
FROM php:7.4.2-apache
RUN pecl install xdebug && docker-php-ext-enable xdebug && docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable pdo_mysql && pecl install apcu && docker-php-ext-enable apcu \
# not yet in linux: xdebug.remote_host = host.docker.internal \n\
&& echo "\n\
xdebug.mode = debug \n\
xdebug.start_with_request = yes \n\
xdebug.client_port = 9003 \n\
xdebug.client_host = 172.18.0.1 \n\
xdebug.log = "C:\xdebug_log\xdebug.log" \n\
xdebug.idekey = VSCODE \n\
" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN apt-get update \
&& apt-get -y --no-install-recommends install libfontconfig1 libxrender1 libxext6 \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
RUN cd /usr/local/etc/php/conf.d/ && \
echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
RUN docker-php-ext-install opcache && docker-php-ext-enable opcache
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-install zip
# GD
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j "$(nproc)" gd
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
and I get this error:
configure: error: unrecognized options: --with-freetype-dir, --with-jpeg-dir
ERROR: Service 'apache_with_php' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev && docker-php-ext-install -j$(nproc) iconv && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && docker-php-ext-install -j$(nproc) gd' returned a non-zero code: 1
I trid to install zlib, because It warns that cannot found it, the I tri to instal zlib and gd, but I get
Building dependency tree...
Reading state information...
E: Unable to locate package libzip-dev
E: Unable to locate package zip
ERROR: Service 'apache_with_php' failed to build: The command '/bin/sh -c apt-get install -y libzip-dev zip && docker-php-ext-install zip' returned a non-zero code: 100
UPDATE 2:
I made some changes in my dockerfile:
FROM php:7.4.2-apache
RUN pecl install xdebug && docker-php-ext-enable xdebug && docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable pdo_mysql && pecl install apcu && docker-php-ext-enable apcu \
# not yet in linux: xdebug.remote_host = host.docker.internal \n\
&& echo "\n\
xdebug.mode = debug \n\
xdebug.start_with_request = yes \n\
xdebug.client_port = 9003 \n\
xdebug.client_host = 172.18.0.1 \n\
xdebug.log = "C:\xdebug_log\xdebug.log" \n\
xdebug.idekey = VSCODE \n\
" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN apt-get update \
&& apt-get -y --no-install-recommends install libfontconfig1 libxrender1 libxext6 \
&& apt-get clean
RUN cd /usr/local/etc/php/conf.d/ && \
echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
RUN docker-php-ext-install opcache && docker-php-ext-enable opcache
RUN apt update && apt install -y zlib1g-dev libpng-dev
RUN docker-php-ext-install gd && docker-php-ext-enable gd
#RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
now there is no error on build, but I get this message:
warning: gd (gd.so) is already loaded!
and when I check the phpinfo()
gd
is not on the extension list
As mentioned in the comments above, your dependencies should be installed in a RUN
, if you delete /var/lib/apt/lists
, you will have to run an apt-get update
again and again afterwards to make sure the data is there, otherwise you will not be able to install anything via apt-get install
.
FROM php:7.4.2-apache
RUN apt-get update \
&& apt-get -y --no-install-recommends install libfontconfig1 libxrender1 libxext6 zlib1g-dev libpng-dev libfreetype6-dev libjpeg62-turbo-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN pecl install xdebug && docker-php-ext-enable xdebug && docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable pdo_mysql && pecl install apcu && docker-php-ext-enable apcu \
# not yet in linux: xdebug.remote_host = host.docker.internal \n\
&& echo "\n\
xdebug.mode = debug \n\
xdebug.start_with_request = yes \n\
xdebug.client_port = 9003 \n\
xdebug.client_host = 172.18.0.1 \n\
xdebug.log = "C:\xdebug_log\xdebug.log" \n\
xdebug.idekey = VSCODE \n\
" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN cd /usr/local/etc/php/conf.d/ && \
echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
RUN docker-php-ext-install opcache && docker-php-ext-enable opcache \
docker-php-ext-configure gd --with-freetype --with-jpeg --with-png && docker-php-ext-install -j$(nproc) gd
RUN /tmp/* /var/tmp/* /usr/share/doc/*
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.