/etc/profile に export utf8 を追加しても機能しない

/etc/profile に export utf8 を追加しても機能しない

debian:stretch のロケールを utf8 に設定しようとしています。次に使用する Docker イメージをビルドします。Dockerfile の一部:

# Set locale
RUN sed --in-place '/en_US.UTF-8/s/^# //' /etc/locale.gen && \
    locale-gen && \
    # Set system locale (add line)
    echo "export LANG=en_US.UTF-8" >> /etc/profile && \
    # Set system timezone (add line)
    echo "export TZ=UTC" >> /etc/profile

私が構築したイメージを使用する Gitlab ジョブ:

$ cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH

if [ "${PS1-}" ]; then
  if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
export LANG=en_US.UTF-8
export TZ=UTC
$ locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

なぜ変更されないのか分かりません。/etc/profileファイルを読み取っていないようです。

答え1

マニュアルページを引用するにはbash(1):

bash が対話型ログイン シェルとして、または オプション付きの非対話型シェルとして呼び出されると、そのファイルが存在する場合は、--loginまずそのファイルからコマンドを読み取って実行します。そのファイルを読み取った後、bash は、、、 をこの順序で 探し 、存在し読み取り可能な最初のファイルからコマンドを読み取って実行します。 この動作を禁止するには、シェルの起動時に オプションを使用できます。/etc/profile
~/.bash_profile~/.bash_login~/.profile--noprofile

<…>

ログイン シェルではない対話型シェルが起動されると、これらのファイルが存在する場合、bash は および からコマンドを読み取って実行します/etc/bash.bashrc~/.bashrcこれは、 オプションを使用して抑制できます--norc。fileオプションは、bash におよび --rcfileではなく file からコマンドを読み取って実行するように強制します 。/etc/bash.bashrc~/.bashrc

関連情報