1

When I do it in amazon linux 2 container, it returned this issue.

bash-4.2# localectl status
Failed to create bus connection: No such file or directory

bash-4.2# timedatectl
Failed to create bus connection: No such file or directory
Miantian
  • 945
  • 1
  • 11
  • 35
  • 1
    What are you trying to accomplish by using `localectl` and `timedatectl`? If you need to set time zone and locale, there are [different](https://stackoverflow.com/q/57607381/4676641) [ways](https://stackoverflow.com/a/28406007/4676641) to accomplish that in Docker. The easiest with `amazonlinux:2` seems to be setting the `LANG` and `TZ` environment variables. – cam Jul 03 '21 at 18:02
  • 1
    @tentative I thought the amazon linux 2 image is the same as the real amazon linux 2 in AWS. I just want to verify the package installation in container first. If you can write your comment as an answer, I'd like to accept it. – Miantian Jul 03 '21 at 23:54

1 Answers1

2

If you need to set time zone and locale, there are different ways to accomplish that in Docker. The easiest with the amazonlinux:2 image seems to be setting the LANG and TZ environment variables:

docker run -e TZ="America/Los_Angeles" -e LANG="en_US.UTF-8" -e LC_ALL="en_US.UTF-8" -it amazonlinux:2

Output:

bash-4.2# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
bash-4.2# date # matching the date in Los Angeles time zone
Sat Jul  3 17:50:38 PDT 2021

Posting my response after your comment asking me to post as answer.

cam
  • 4,409
  • 2
  • 24
  • 34