Docker Community Forums

Share and learn in the Docker community.

How can i edit php.ini file in docker container? - for windows docker

How can i edit php.ini file in docker container? please give good explanation

Good evening,

there are different approaches to fulfill this task.
The following ones come to my mind - sorted from worst to best.

You can either open a shell into your running container and then edit the file. docker exec -it <containername> bash or docker exec -it <containername> ash and then use vim to edit the file. Maybe you need to install vim or the editor of your choice. This is not a good idea because the most common use of php (the php-fpm-image) reads the file on startup of the container and if you create a new instance of the image (= a new container) you have the same issue that the file contains content you do want to change.

You can copy a file from the running container to your docker-host docker cp ....., edit the file on your host and copy it back into the container. Advantage over the idea described above: you don’t need to install additional software into the container. But you still have the other disadvantages as above.

Another idea is to create the file on your host (or copy it from a running container to your host) and edit it according to your needs. Then you can create a Dockerfile which creates a new image based on your php-image which ADDs or COPYs the modified php.ini into the image. Then every instance of this image (aka a container) contains the modified php.ini.

Best idea (at least in my eyes) is to create the file on your host (or copy it from a running container to your host) and edit it according to your needs. Then you stop your PHP-container and remove it. Now you create your PHP-container again, but this time you mount the php.ini-file located on your host into the container docker run --volume .... Of course the same thing is possible with docker-compose.

1 Like