# Set system timezone from node-RED

**URL:** <https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809>\
**Category:** General\
**Tags:** docker\
**Created:** [26 June 2025 12:52 UTC](https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809 "2025-06-26T12:52:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![aitor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aitor/32/97363_2.png) [@aitor](https://discourse.nodered.org/u/aitor)\
**Post date:** [26 June 2025 12:52 UTC](https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809/1 "2025-06-26T12:52:22Z")

</div>

Hi,

Im trying to set timezone inside the Docker container from node-RED this way:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2e0bbdd41fc346ff30d63ce595b3bbc6062501a6.png)  
The idea is to inject timezone so I can easily set system timezone. Im running v4.0.5 on docker.

This method throws an error because the Node-RED user isn’t root, so I can’t modify `/etc/localtime` .  
Any idea how I could work around this?

Thanks!

> **codeHere**
>
> ```auto
> [{"id":"eecaed65c5c38d92","type":"inject","z":"fbf8a7aab69c85cc","name":"timezone EUROPE CENTRAL","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ln -s /usr/share/zoneinfo/Europe/Madrid /etc/localtime","payloadType":"str","x":192,"y":112,"wires":[["d6e42ee8f919fa9d"]],"icon":"font-awesome/fa-clock-o"},{"id":"631286a30962de4b","type":"exec","z":"fbf8a7aab69c85cc","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"execTimezone","x":512,"y":128,"wires":[["893ac4a1dba6c1a8"],[],[]]},{"id":"b616b072dfe7098c","type":"inject","z":"fbf8a7aab69c85cc","name":"timezone MEXICO","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ln -s /usr/share/zoneinfo/America/Mexico_City /etc/localtime","payloadType":"str","x":162,"y":152,"wires":[["b1533089fe82692e"]],"icon":"font-awesome/fa-clock-o"},{"id":"15fbd12eee3ea874","type":"debug","z":"fbf8a7aab69c85cc","name":"debug 90","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":673,"y":128,"wires":[],"l":false},{"id":"041ab52e33d9f71d","type":"inject","z":"fbf8a7aab69c85cc","name":"timezone CHINA","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime","payloadType":"str","x":152,"y":72,"wires":[["74557fbc1d3ab1cc"]],"icon":"font-awesome/fa-clock-o"},{"id":"893ac4a1dba6c1a8","type":"change","z":"fbf8a7aab69c85cc","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"RESTART CONTAINER","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":623,"y":128,"wires":[["15fbd12eee3ea874"]],"icon":"node-red/arrow-in.svg","l":false},{"id":"5391b1db258b29e0","type":"inject","z":"fbf8a7aab69c85cc","name":"timeNow","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":580,"y":176,"wires":[["15fbd12eee3ea874"]],"icon":"font-awesome/fa-question-circle"},{"id":"d6e42ee8f919fa9d","type":"junction","z":"fbf8a7aab69c85cc","x":384,"y":112,"wires":[["631286a30962de4b"]]},{"id":"b1533089fe82692e","type":"junction","z":"fbf8a7aab69c85cc","x":384,"y":152,"wires":[["631286a30962de4b"]]},{"id":"74557fbc1d3ab1cc","type":"junction","z":"fbf8a7aab69c85cc","x":384,"y":72,"wires":[["631286a30962de4b"]]}]
> 
> ```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 June 2025 13:08 UTC](https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809/2 "2025-06-26T13:08:20Z")

</div>

> [@aitor](#):
>
> Im running v4.0.5 on docker.

That makes it even more difficult as one of the reasons for using Docker is to keep the system safe from applications trying to mess with the OS settings.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [26 June 2025 13:21 UTC](https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809/3 "2025-06-26T13:21:19Z")

</div>

There is of course a command to change the timezone:

```auto
sudo timedatectl set-timezone Asia/Shanghai

```

To use it you need

- To be able to see the timedatectl command from within docker.
- Passwordless sudo access for the Node-red user.

If you can do that I've no idea if it would change the timezone outside of the docker container - which as @Colin says is designed to prevent such jiggery-pokery.

---

<div class="post-metadata">

**Author:** ![aitor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aitor/32/97363_2.png) [@aitor](https://discourse.nodered.org/u/aitor)\
**Post date:** [26 June 2025 13:33 UTC](https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809/4 "2025-06-26T13:33:36Z")

</div>

I believe I miscommunicated earlier. 😅

What I actually need is to **change the timezone inside the Docker container** , not the host system's timezone. Also, using `sudo` isn't an option because **Alpine-based Docker images (like the one used by Node-RED)** typically **don’t include `sudo` by default**.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 June 2025 14:33 UTC](https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809/5 "2025-06-26T14:33:23Z")

</div>

If you open a terminal window inside the docker container, what command would you use to do what you want?

---

<div class="post-metadata">

**Author:** ![aitor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aitor/32/97363_2.png) [@aitor](https://discourse.nodered.org/u/aitor)\
**Post date:** [26 June 2025 14:59 UTC](https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809/6 "2025-06-26T14:59:37Z")

</div>

I'm using the same commands (`ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime`) , but I tried to simplify the process by triggering them through the inject node. I suspect the issue is related to permissions—when I run the commands directly from the terminal, they execute with root privileges, which might be why they work there but not through the inject node.

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [26 June 2025 15:01 UTC](https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809/7 "2025-06-26T15:01:33Z")

</div>

The correct way is to pass the TZ environment variable into the container.

e.g

```auto
docker run -e TZ=Europe/London -p 1880:1880 nodered/node-red:latest

```

---

<div class="post-metadata">

**Author:** ![aitor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aitor/32/97363_2.png) [@aitor](https://discourse.nodered.org/u/aitor)\
**Post date:** [27 June 2025 09:35 UTC](https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809/8 "2025-06-27T09:35:54Z")

</div>

Ok! Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 July 2025 09:36 UTC](https://discourse.nodered.org/t/set-system-timezone-from-node-red/97809/9 "2025-07-11T09:36:48Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
