Docker Container Timezone Change Guide

Changing the timezone in a Docker container can be achieved by following these steps:

To access the running container: use the following command to enter the container, where the container_id is either the container’s ID or name.

docker exec -it container_id /bin/bash

Install the time zone setting tool by running the following command inside the container: tzdata.

apt-get update
apt-get install -y tzdata

3. Set the time zone by executing the following command to choose the desired time zone, such as setting it to Shanghai time zone.

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo "Asia/Shanghai" > /etc/timezone

4. Verify the time zone setting: Execute the following command to verify if the time zone has been successfully changed.

date

5. Exit the container: execute the following command to leave the container.

exit

6. Restart the container: If you need the time zone setting to take effect, you can restart the container.

docker restart container_id

This way, you can successfully change the time zone in a Docker container.

bannerAds