Amending Docker installation

Hello all,

I’ve been following the Sitepoint tutorial/book PHP Novice to Ninja, and have used the info to build my own CMS. I followed the instruction contained with in the book for how to set up Docker, but don’t really understand how it works (or how to modify it)

I attempting to use a php function called imagecreatefromjpeg() which my installation of Docker doesn’t recognise [Fatal error: Uncaught Error: Call to undefined function imagecreatefromjpeg() ]

Apparently I need to install GD Library. I have found some forums that suggest i need to add

RUN docker-php-ext-install gd

to my Dockerfile, but I can’t figure out how to make Docker reconfigure with this command

Any pointers much appreciated

Just build your image:

docker build -t <your-image-name> .

Substitute with yours

. means the Dockerfile is in the same directory you are running the command

If you have premium access to Sitepoint. I highly recommend this. Is one of the best tutorial on Docker I have seen out there.

1 Like

Hey.

Thanks for the the pointer. I tried that (with a few caveats listed below) and got the following error:
ERROR: failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory

I think I’m running a very bespoke Docker set up as detailed here:

The folder containing all the Docker things doesn’t actually have a Dockerfile, it has a PHP.Dockerfile

Caveat: I don’t even know what a Docker image is and what i should type there (and I have tried to Google the matter and am no clearer). I’m assuming this will create a new Image so I can type a new name, but if it’s an existing name it could be related to the following:

My Docker folder contains a folder called ‘websites’ in which I can put further folders to develop sites and run them on the browser using ‘websitename.v.je’

So I’m presuming these might be the images. But I’ve tried it both ways (new image name & existing website folder) with no luck.

I tried copying the whole folder and running ‘docker compose up’ which did a lot of things in the terminal but eventually came to the error:

failed to solve: process “/bin/sh -c docker-php-ext-install gd” did not complete successfully: exit code: 1

I will add that tutorial to my list of things to learn but I’m not ready for a dive into learning to set up Docker at the moment, just hoping for a quick tweak to my existing environment

By default the the docker file is dockerfile, but if the name is different then you have to point to it:

docker build -f ../path/to/your/Dockerfile . 

However from the link you put, I can see they are using docker compose. Inside there I can see, a between others, this:

php:
    build:
        context: .
        dockerfile: PHP.Dockerfile
    volumes:
        - ./websites:/websites

In that case you can build the docker compose, which will build, in between others, your docker file:

docker-compose build

Run this where the docker-compose.yml is.

Think of image as a template created from the docker file, and the container as the instance of the image

1 Like

Hey, thanks for taking the time to look into this.

I tried what you said with the following at the bottom of my PHP.Dockerfile

RUN docker-php-ext-install gd

and was met by this error:

docker-php-ext-install gd" did not complete successfully

So I did a bit of googling and via the following:

https://stackoverflow.com/questions/39657058/installing-gd-in-docker and a comment at the bottom about what to do with php 8.2 (mine is 8.1.7)

i tried

RUN apk add libpng-dev

RUN docker-php-ext-install gd

Which seemed to build successfully and launched the container (if thats the right word)

However the functions provided by the GD library are still not there:

! ) Fatal error: Uncaught Error: Call to undefined function imagecreatefromjpeg() in /websites/image-upload-test/public/imageUpload.php on line 60

The bit I’m potentially missing is in the comment I am refering to there is the following:

composer.json:

"require": { "php": ">=8.2", "ext-gd": "*",

But I can’t see where to put that, and I don’t think i have composer installed.

This Docker Hub claim to be the official PHP Docker hub.

https://hub.docker.com/_/php/

In the section, How to install more PHP extensions.

Seems to have an example how to install gd.

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

Good luck.