'Loading custom php.ini on Docker (image: php:8.1.2-apache)
I'm trying to load my custom .ini file
I've tried mounting the /usr/local/etc/php/conf.d directory to ./php so that I can add .ini files, but it doesn't work, I mean the local directory php gets created but it's empty.
One more thing I'm curious about, what if the same config already exists in any of those already loaded .ini file, will my custom .ini will overwrite those? (That's actually what I want).
This is my Dockerfile
FROM php:8.1.2-apache
RUN apt-get update
# 1. development packages
RUN apt-get install -y \
git \
zip \
curl \
sudo \
unzip \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libzip-dev \
libfreetype6-dev \
g++
# 2. apache configs + document root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers
# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install \
bz2 \
intl \
iconv \
bcmath \
opcache \
calendar \
pdo_mysql \
pdo_mysql \
zip
# 5. composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
And here's the docker-compose.yml
version: '3.5'
services:
# Laravel App
laravel:
build:
context: '.'
restart: always
volumes:
- .:/var/www/html
# - ./php:/usr/local/etc/php/conf.d (This doesn't work)
# MySQL
mysql:
image: mysql:8
restart: always
volumes:
- ./run/var:/var/lib/mysql
environment:
- MYSQL_DATABASE=${DB_DATABASE}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
# Meilisearch
meilisearch:
image: getmeili/meilisearch:latest
restart: always
volumes:
- ./meilisearch/data.ms:/data.ms
environment:
- MEILI_MASTER_KEY=${MEILISEARCH_KEY}
networks:
default:
name: nginxproxymanager_default
external: true
Many thanks in advance :)
Solution 1:[1]
Set path direct to file
volumes:
- ./:/var/www
- ./Docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
Check my docker-compose for more information: https://github.com/JavierAgueroCL/docker-php7.4-with-db-extensions/blob/master/docker-compose.yml
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JavierAgueroCL |
