Don't install gd manually. There's the docker-php-ext-install
for that.
Inside the dockerfile, add:
RUN docker-php-ext-install gd
There is a bit of an annoyance with docker-php-ext-install
that you have to figure out manually what dependencies you'll need. They don't resolve automatically. Due to this, the command will crash on its own, with:
configure: error: png.h not found.
If you look for the error, you will realize that you need libpng-dev
.
Hence finally, the whole Dockerfile
should look something like this:
FROM php:5.6-cli
RUN apt-get -qq update && apt-get -qq install libpng-dev
RUN docker-php-ext-install gd > /dev/null
docker-php-ext-install is a bit verbose in its output, hence I like to pipe its output to /dev/null
. Errors and warnings will still be printed.
You can check that the image has the proper extension by running the image:
docker build -t php-gd .
docker run php-gd /bin/bash -c "php -m | grep gd"
Will print:
gd
Same within a docker-compose stack:
docker-compose.yml
:
gd-example:
build: .
tty: true
docker-compose up --build -d
docker ps // to find container's name. You may also set in the config
docker exec -it docker_gd-example_1 php -m | grep gd
Two sidenotes:
From your question is was not clear if you built your container and then run apt-get install php5-gd
from it. If so, then that would only instal php5-gd within that container and everytime you recreate it, it will be gone. Always add stuff to a container from within the Dockerfile
.
Give php:7.1-cli
a try. Do you really need to support php 5.6? ;)