How do I edit php.ini in a docker container?

So I'm running the wordpress docker container and I want to increase the upload file size limit set in php.ini. My problem is I can't find that file anywhere.

I installed the container with a docker-compose file.


Solution 1:

For development purpose you could just bind mount it from the host to the container take a look here

To a production environment you could think to personalize the container by build your own on top of it.

For example in your docker-compose is declared the docker image of wordpress calleds wordpress:5.4.0-php7.2-fpm-alpine

you can create your own Dockerfile to edit the base image, it will look like

FROM wordpress:5.4.0-php7.2-fpm-alpine
COPY ./php.ini /etc/php/7.2/apache2/php.ini

the ./php.ini is your modified version and the path is the destination.

Bothe above method are persistent and can be applied in build time and start time. But what about runtime, can change modification without restart the container?

Sure you can, you can invoke the docker cp command:

docker cp ./php.ini container_name:/etc/php/7.2/apache2/php.ini

but the change are not persistent, NOTE: above command can be executed bidirectionally (put in container and take from the container)

To persist the modification you done there is another way I'm aware:

Commit the container modification, more info here

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]