thecodingmachine / docker-images-php

A set of PHP Docker images
MIT License
790 stars 139 forks source link

Feature Request: Install locales through environment variables #212

Open moqmar opened 4 years ago

moqmar commented 4 years ago

Expected Behavior

Some stuff in PHP depends heavily on locales, so I'd expect locales to be supported by a general-purpose PHP container.

Current Behavior

I need to create a custom Dockerfile to install and install the neccessary locales:

RUN { echo en_GB.UTF-8 de_DE.UTF-8; echo C.UTF-8; } | DEBIAN_FRONTEND=teletype dpkg-reconfigure locales
ENV PHP_INI_INTL__DEFAULT_LOCALE=de_DE.UTF-8

Possible Solution

Add an environment variable LOCALES="en_GB.UTF-8 de_DE.UTF-8" that generates the locales on container start. Setting PHP_INI_INTL__DEFAULT_LOCALE can be an independent option.

Context

I want to use ProcessWire, and am trying to create as few custom Docker images as possible.

Your Environment

mbrodala commented 1 year ago

Maybe helpful: https://askubuntu.com/questions/683406/how-to-automate-dpkg-reconfigure-locales-with-one-command

daedeloth commented 2 weeks ago

+1.

I solved it for now by adding to my Dockerfile:

USER root
RUN apt-get update && apt-get install locales-all && apt-get clean

USER docker
mbrodala commented 2 weeks ago

That supposedly installs all locales, even not necessary ones. We currently use this:

USER root

ARG LOCALES="de_DE.UTF-8"
RUN for l in ${LOCALES}; \
        do sed -i -e "s/# \(${l} .*\)/\1/" /etc/locale.gen; \
    done
RUN dpkg-reconfigure -f noninteractive locales

USER docker

Still it would be nice if this or something similar was available by default without a custom build.

daedeloth commented 2 weeks ago

Cool, that is indeed less drastic :) Thanks, will switch to that. *edit: actually that doesn't seem to work with thecodingmachine/php:8.0-v4-slim-apache, so switched to:

USER root
RUN apt-get update && apt-get install -y language-pack-nl && apt-get clean;
USER docker
mbrodala commented 2 weeks ago

Not sure what "doesnt' seem to work" mean exactly. We're using this for ages and various image versions just fine:

$ locale -a
C
C.UTF-8
POSIX
de_DE.utf8
daedeloth commented 2 weeks ago

0.116 sed: can't read /etc/locale.gen: No such file or directory

mbrodala commented 2 weeks ago

Ah you are right, we obviously install the locales package before that:

USER root

RUN apt-get update \
    && apt-get install -y \
        ... \
        locales \
        ... \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

ARG LOCALES="de_DE.UTF-8"
RUN for l in ${LOCALES}; \
        do sed -i -e "s/# \(${l} .*\)/\1/" /etc/locale.gen; \
    done
RUN dpkg-reconfigure -f noninteractive locales

USER docker