LoginSignup
13
5

More than 3 years have passed since last update.

Failed to create bus connection: No such file or directoryとなった時の対応方法

Posted at
  • 環境 : Dockerで作ったコンテナのCentOS Linux release 7.8.2003 (Core)

コンテナでロケールを設定しようとしたら怒られた

# 日本時間に設定したかった
$ date
Mon Jun 15 01:32:49 UTC 2020

$ timedatectl
Failed to create bus connection: No such file or directory
$ localectl status
Failed to create bus connection: No such file or directory

原因 : ディストリビューションの設定コマンドは使えないから

CentOS7のロケール設定コマンドである localectl はコンテナ上で実行できません。
systemctlなどと同様にエラーになります。
Dockerfileで日本語ロケールを設定する方法。およびロケールエラーの回避方法。 - Qiita

環境変数を設定する

注意 : 操作はすべてroot権限で実行する

# 1. 日本語のロケールを追加する
$ localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
$ locale -a
C
POSIX
en_US.utf8
ja_JP.utf8

# 2. 全ユーザーに適用するように/etc/profileに環境変数を設定する
$ vi /etc/profile
$ cat /etc/profile | grep -e LANG -e LC
LANG="ja_JP.UTF-8"
LANGUAGE="ja_JP:ja"
LC_ALL="ja_JP.UTF-8"

# 3. 反映する
$ source /etc/profile
$ date
Mon Jun 15 11:24:15 JST 2020

Dockerfileで設定する場合

出典 : Dockerfileで日本語ロケールを設定する方法。およびロケールエラーの回避方法。 - Qiita

RUN localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
ENV LANG="ja_JP.UTF-8" \
    LANGUAGE="ja_JP:ja" \
    LC_ALL="ja_JP.UTF-8"
13
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
5