skip to Main Content

I am using docker compose, I want to open few extensions and edit. So basically I want to open php.ini file. How can we exactly do that. However some solutions I read are saying to do changing in docker_compose.yaml, I am also sharing the file.
I am using php laravel framework, and running application on ubuntu server. Any help is highly appreciated.
Thanks in advance.
docker_compose.yaml look something like this.

version: '3.7'

services:
    php:
        container_name: eesotne-fpm
        build: ./deployment/fpm
        image: eesotne-fpm
        entrypoint: ./deployment/fpm/entrypoint.sh
        volumes:
            - ./:/eesotne
        depends_on:
            - mysql
            - redis
    mysql:
        container_name: eesotne-mysql
        image: mysql:5.7
        volumes:
            - "mysql_data:/var/lib/mysql"
        restart: always
        environment:
            - MYSQL_ROOT_PASSWORD=secret
            - MYSQL_DATABASE=eestone
            - MYSQL_USER=eestone
            - MYSQL_PASSWORD=secret

    admin:
        container_name: eesotne-adminer
        image: adminer
        restart: always
        depends_on:
            - mysql
        ports:
            - 8081:8080

    phpmyadmin:
        container_name: eesotne-phpmyadmin
        image: phpmyadmin/phpmyadmin
        links:
            - mysql
        ports:
            - 8080:80
        environment:
            MYSQL_USER: eesotne
            MYSQL_PASSWORD: secret
            MYSQL_ROOT_PASSWORD: secret
            MYSQL_DATABASE: eesotne
            PMA_HOST: mysql
            PMA_PORT: 3306

    nginx:
        container_name: eesotne-nginx
        image: nginx
        ports:
            - "80:80"
        volumes:
            - ./deployment/nginx/default.conf:/etc/nginx/conf.d/default.conf
            - ./:/eesotne
            - ./deployment/logs/nginx:/var/log/nginx
        depends_on:
            - php

    redis:
        container_name: eesotne-redis
        image: redis
        volumes:
            - redis_data:/data

    portainer:
        container_name: eesotne-portainer
        image: portainer/portainer
        ports:
            - "9000:9000"
        command: -H unix:///var/run/docker.sock
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
            - portainer_data:/data
    echo:
        container_name: eesotne-echo
        build: ./deployment/echo
        entrypoint: ./deployment/echo/entrypoint.sh
        working_dir: "/usr/src/app"
        depends_on:
            - redis
        volumes:
            - "./:/usr/src/app"
volumes:
    redis_data:
    portainer_data:
    mysql_data:

2

Answers


  1. You need to create your custom image.

    Not sure about how you are building your images but it seems you already have your docker files with your specifications.

    If you are using an official image as base image to enable the image it is very easy in the construction of the docker image.

    To configure the php.ini the good practice is have a preconfigured php.ini and copy it to the image to replace the default.

    FROM php:7.3-fpm
    RUN docker-php-ext-install pdo pdo_mysql opcache
    COPY config/php.ini /php.init
    RUN mv /php.ini "$PHP_INI_DIR/php.ini"
    

    Hope this can help.

    Another dirty method could be update your php.ini with a shell script using the sed command to replace with your values.

    Login or Signup to reply.
  2. You mentioned some solutions require you to edit your docker-compose file, but I’m not entirely sure if that’s an issue for you based on your post.


    You could map a volume to a local directory and give yourself free rein to add any PHP configuration in the future. If your container is based on the official image, you can do something like this:

    volumes:
    - ./php-conf:/usr/local/etc/php/conf.d
    

    Which would map your local php-conf directory to the directory configured to scan for more .ini files. You can also override this with the PHP_INI_SCAN_DIR env variable:

    It is possible to configure PHP to scan for .ini files in a directory after reading php.ini. This can be done at compile time by setting the –with-config-file-scan-dir option. In PHP 5.2.0 and later, the scan directory can then be overridden at run time by setting the PHP_INI_SCAN_DIR environment variable.

    In there you can put whatever configuration you’d like to override in .ini files.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search