Skip to content

Instantly share code, notes, and snippets.

@shov
Created May 21, 2018 09:36
Show Gist options
  • Save shov/f34541feae29afedd93208df4bf428f3 to your computer and use it in GitHub Desktop.
Save shov/f34541feae29afedd93208df4bf428f3 to your computer and use it in GitHub Desktop.
Docker PHP 7.2 fpm with GD jpg, png suppot
FROM php:7.2-fpm
# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# make sure apt is up to date
RUN apt-get update --fix-missing
RUN apt-get install -y curl
RUN apt-get install -y build-essential libssl-dev zlib1g-dev libpng-dev libjpeg-dev libfreetype6-dev
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 9.2.0
# Install nvm with node and npm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash \
&& source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
WORKDIR /var/www/html
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN usermod -u 1000 www-data
@arimourao
Copy link

Hi there. I'm having a hard time to add GD to my dockerfile. I followed your tips but even so I can't install a dependency that requires GD. It says it is still missing. Any ideas?

@shov
Copy link
Author

shov commented Dec 18, 2019

@arimourao

Hey, have you solved it? Which version of php base image? Exactly 7.2-fpm? Some useful information about how to reproduce your case?

@arimourao
Copy link

Hey there. Yeah I solved, your Gist here helped me a lot. Thanks for your time.

@kieste
Copy link

kieste commented May 22, 2020

Thanx! This solved my problems with GD Lib Jpeg Support! After hours of searching through SO.

@andreasathanasopoulos
Copy link

Thanks, working like a charm!

@beisong7
Copy link

Thanks, line 26 and 27 worked for me

@unlocomqx
Copy link

Line 26 & 27 probably saved 3 hours of googling

@Antarian
Copy link

I only used lines 26, 27 for my php 7.4 docker and discovered that they needs to be updated to:

RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
    && docker-php-ext-install gd

--with-freetype instead of --with-freetype-dir

@Tobiaqs
Copy link

Tobiaqs commented Feb 12, 2021

Check out https://www.php.net/manual/en/image.installation.php, it shows all the required parameters for the different image formats.

@ghtropic
Copy link

Thank you! (lines 26,27)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment