如果你在主机 PC 上输入 locale -a
,你一定会发现像 fr_FR
这样的东西。但是在容器中,默认情况下,大多数镜像都不提供法语语言。
以下是一个最小化的示例,供你安装法语语言参考:
test.php:
<?php setlocale(LC_ALL, 'fr_FR'); echo strftime("%A %d %B %Y");
Dockerfile:
FROM php
COPY test.php /
RUN apt-get update; \
apt-get install -y locales; \
sed -i '/^#.* fr_FR.* /s/^#//' /etc/locale.gen; \
locale-gen
RUN locale -a
RUN php /test.php
执行:
$ docker build -t abc:1 .
Sending build context to Docker daemon 3.072kB
Step 1/5 : FROM php
---> 7a9e4bdd6171
Step 2/5 : COPY test.php /
---> 705d4f7695e4
Step 3/5 : RUN apt-get update; apt-get install -y locales; sed -i '/^#.* fr_FR.* /s/^#//' /etc/locale.gen; locale-gen
---> Running in 1c9d6012e7b9
...
Generating locales (this might take a while)...
Generation complete.
Generating locales (this might take a while)...
fr_FR.ISO-8859-1... done
fr_FR.UTF-8... done
fr_FR.ISO-8859-15@euro... done
Generation complete.
Removing intermediate container 1c9d6012e7b9
---> ff1733e34ad0
Step 4/5 : RUN locale -a
---> Running in bd21cd6c14e8
C
C.UTF-8
POSIX
fr_FR
fr_FR.iso88591
fr_FR.iso885915@euro
fr_FR.utf8
fr_FR@euro
french
Removing intermediate container bd21cd6c14e8
---> 699d9918f95f
Step 5/5 : RUN php /test.php
---> Running in 49316730728c
mardi 22 juin 2021Removing intermediate container 49316730728c
---> c8cc561fd306
Successfully built c8cc561fd306
Successfully tagged abc:1
说明:
/etc/locale.gen
中的 fr_FR
被注释掉了,我们可以使用 sed
命令来取消注释。locale-gen
命令生成法语语言环境。mardi 22 juin 2021
。RUN apt-get update && apt-get install -y locales