Miantian
Miantian

Reputation: 1075

How to use localectl and timedatectl in amazon linux 2 image?

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

Upvotes: 1

Views: 2018

Answers (1)

cam
cam

Reputation: 5198

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.

Upvotes: 2

Related Questions