Installing Gd in Docker

Installing GD in Docker

You should add the libpng-dev package to your Dockerfile:

FROM php:5.6-apache

RUN docker-php-ext-install mysql mysqli

RUN apt-get update -y && apt-get install -y sendmail libpng-dev

RUN apt-get update && \
apt-get install -y \
zlib1g-dev

RUN docker-php-ext-install mbstring

RUN docker-php-ext-install zip

RUN docker-php-ext-install gd

Then go to directory with Dockerfile and run:

docker build -t sitename .

It worked in my case:

Removing intermediate container f03522715567
Successfully built 9d69212196a2

Let me know if you get any errors.

EDIT:

You should see something like this:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
sitename latest 9d69212196a2 19 minutes ago 414 MB
<none> <none> b6c69576a359 25 minutes ago 412.3 MB

EDIT2:

Just to double check everything:

Please run the docker build command this way:

docker build -t sitename:1.0 .

(adding :1.0 should not change anything, I added it just to have additional row in docker images output)

Then start the container:

docker run --name sitename_test -p 80:80 sitename:1.0

It should work just fine.

I assumed that apache is using standard port (80) - maybe you need to adjust that. If you have other services/containers listening on port 80 you can make your container listening on other port:

docker run --name sitename_test -p 8080:80 sitename:1.0

That will redirect the traffic from port 8080 to port 80 "inside" the container.

Normally you run container in the background. To do this add the -d option to the docker run command (but for testing purposes you can omit -d to see output in the console).

If you decide to run container in the background you can check logs using docker logs sitename_test. To follow the logs (and see updates in logs) use -f option:

docker logs -f sitename_test

Installing GD extension in Docker

You can try to add these settings in Dockerfile:

FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd

Official documentation. Hope it's help you.

install Gd extension on docker

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


Related Topics



Leave a reply



Submit