Node Red Docker container displays incorrect time

I have an unusual issue that probably has a simple solution that I have been unable to figure out so far…

I’m running Home Assistant using Docker on Ubuntu 18.04 (not HASS.io, just the Home Assistant container). In a separate container, I’m running Node-RED which connects just fine to Home Assistant.

My issue is the Node-RED container displays the incorrect local time of UTC instead of UTC - 5. I’ve tried many things including setting the container’s environment variable to local time, mapping \etc\localtime and \etc\timezone volumes, etc…

This is the only container out of 12 services that have this issue. When I remote into the container and run date, it clearly shows UTC instead of UTC-5.

Any suggestions?

did you map /etc/localtime and /etc/timezone to the container in your docker run comand? i.e, something like

docker run -d --name=nodered -v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro .....

Yes, in the Docker compose file, I’ve mapped both volumes (and tried one at a time) as well as set the environment variable such as:

    volumes:
      - /opt/docker/node-red/:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    environment:
      - TZ=America/New York

two things:

  1. I think it’s one or the other - you either need the TZ variable or the time files, not both
  2. That’s not a valid timezone name, it should be America/New_York (you’re missing the underscore)

My guess is your invalid TZ name is causing your container to default to UTC

I’m having the same issue too with node_red. I tried the volume mount and variable. I still got the time messed up. I even deleted the container and the image files.

Good catch - I corrected the TZ environment variable, removed the volume mappings, and then restarted the container - still no luck.

I’ve also tried each combination of environment + volume mapping with container restarts each time and the output of node-red container still shows UTC.

If it helps here’s my docker-compose file for node-red:

version: '3'

services:
  nodered:
    container_name: nodered
    image: nodered/node-red-docker:v8
    volumes:
      - /var/homeserver/nodered:/data
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
    user: '1000'
    network_mode: host
    restart: unless-stopped
    labels: 
      - com.centurylinklabs.watchtower.enable=true

That label is so that the watchtower sevice will auto-update my container when a new one is released.

I just confirmed that when I attach to the node-red container with:

 docker exec -it nodered /bin/bash

and issue a ‘date’ command - I get the current date and time in my timezone.

Wait - how are you checking the current time in Node Red? If you are going by the output of the “inject” node’s timestamp - that’s always in unix time, and when you click it in the debug window, it’s converted to UTC always as far as I know.

If you install something like BigTimer, it will use your computer’s local time.

The timestamp on any flow shows the incorrect UTC time. Just so I’m clear, are you saying that’s expected to display in UTC?

These two screenshots show the difference between the container console (expected time) vs. the actual NodeRED flow (unexpected UTC time).


Imgur

Well, I guess I’m saying that’s how it works on my setup. :slight_smile:

Ha, appreciate all your help!

I’ve found that this works to have Node-Red show local time when looking at the last triggered time in Node-Red. Obviously, use your timezone instead of Brussels.

3 Likes

Thank you, that worked!!

Thanks,
I’ve found what I was looking for here. I was missing time zone setup