ntopng icon indicating copy to clipboard operation
ntopng copied to clipboard

[Alpine Linux] Cannot change TZ due to missing timedatectl, inside the container

Open walteroa2023 opened this issue 2 years ago • 20 comments

Environment:

  • OS name: Docker image based on Alpine
  • OS version: 3.18
  • Architecture: amd64
  • ntopng version/revision: Community v.5.6.230814 (Ubuntu 22.04.2 LTS)

What happened: docker image does not include timedatectl. Not able to change TZ to my preferences (America/Argentina?/Buenos_Aires) inside the container.

How did you reproduce it? sudo docker exec -it ntopng bash

walteroa2023 avatar Aug 20 '23 00:08 walteroa2023

What is the exact page which is leading to this? Could you provide a screenshot? Please note a docker container requires privileges to change the TZ as it affects the host OS, that should be the reason.

cardigliano avatar Aug 21 '23 13:08 cardigliano

What is the exact page which is leading to this? Could you provide a screenshot? Please note a docker container requires privileges to change the TZ as it affects the host OS, that should be the reason.

Sorry to disagree, but does not affect the host OS....

the pages we are referring to are: (see attached images)

  1. dashboard page, bottom
  2. root privileges inside the container
  3. date inside the container
  4. timedatectl missing using bash
  5. date in the host system (Alpine)

So, any clue?

ntop1 ntop2 ntop3 ntop4 ntop5

So?

walteroa2023 avatar Aug 23 '23 03:08 walteroa2023

@walteroa2023 are you saying that you are not able to manually set the TZ using timedatectl, or that ntopng is trying to do that?

cardigliano avatar Aug 23 '23 07:08 cardigliano

@walteroa2023 are you saying that you are not able to manually set the TZ using timedatectl, or that ntopng is trying to do that?

I'm saying, as soon as the image comes with UTC by default, Im not able manually set the TZ using timedatectl

any workaround?

walteroa2023 avatar Aug 23 '23 14:08 walteroa2023

Closing as it does not depend on ntopng

cardigliano avatar Sep 08 '23 13:09 cardigliano

perhaps not (still disagree), but please bring me a solution to change the TZ inside the container, just because environment variable does not work... keep this thread open, or do you want me to open a new one?

walteroa2023 avatar Sep 08 '23 13:09 walteroa2023

Reopened, but you said your issue is related to timedatectl missing in the container, preventing you from setting the timezone, so not sure why you say this is still an ntopng issue

cardigliano avatar Sep 08 '23 14:09 cardigliano

simple answer, who create the image should take care on environment variables and be sure all of them passed correctly to container itself. This is not the case, just because my environment variables are set for a particular timezone, and the container doesn't care...

So, my docker-compose file is pretty simple!! see below image

The embedded OS (Ubuntu) on ntopng image remain UTC, which is not usable at all. I tried to run some commands inside container thru bash, but commands (like timedatectl) are not available.

So, please provide a workaround for this. I guess I wasn't the only one asking for it.. but i didn't find any solution in forum.

Awaiting your further investigation, my sincerely greetings... Walter

walteroa2023 avatar Sep 08 '23 14:09 walteroa2023

More evidence something went wrong at the time of taking environment variables:

from portainer view: image

from ntopng: image

so, here is when you come with your magic solution ;)

walteroa2023 avatar Sep 08 '23 23:09 walteroa2023

I was digging a bit and it seems docker uses GMT by default, and using a local timezone requires the installation of "tzdata", in Docker that would translate in the below in the Dockerfile:

RUN apt-get update &&
apt-get install -yq tzdata &&
ln -fs /usr/share/zoneinfo/America/Buenos_Aires /etc/localtime &&
dpkg-reconfigure -f noninteractive tzdata

ENV TZ="America/Buenos_Aires"

cardigliano avatar Sep 11 '23 15:09 cardigliano

Thx a lot for this huge advance!! Now, let me help to understand how can it be fixed...

Should I run those commands where?

  • in the terminal console inside your ntopng image?
  • in my host terminal? (reminder: Alpine distro)
  • or should I create a new image by my own?

thx again, we are close to fix it !!!

El lun, 11 sept 2023 a las 12:59, Alfredo Cardigliano (< @.***>) escribió:

I was digging a bit and it seems docker uses GMT by default, and using a local timezone requires the installation of "tzdata", in Docker that would translate in the below in the Dockerfile:

RUN apt-get update && apt-get install -yq tzdata && ln -fs /usr/share/zoneinfo/America/Buenos_Aires /etc/localtime && dpkg-reconfigure -f noninteractive tzdata

ENV TZ="America/Buenos_Aires"

— Reply to this email directly, view it on GitHub https://github.com/ntop/ntopng/issues/7775#issuecomment-1714170694, or unsubscribe https://github.com/notifications/unsubscribe-auth/BB7TLMSXZ3RYJE5C6BRFXK3XZ4YMXANCNFSM6AAAAAA3W4QWUM . You are receiving this because you were mentioned.Message ID: @.***>

--

Walter Altimora@.***

walteroa2023 avatar Sep 12 '23 00:09 walteroa2023

There are 2 options: run the commands in the container, or build a new container adding those commands to the Dockerfile. There are sample dockerfiles available at https://github.com/ntop/docker-ntop

cardigliano avatar Sep 12 '23 07:09 cardigliano

There are 2 options: run the commands in the container, or build a new container adding those commands to the Dockerfile. There are sample dockerfiles available at https://github.com/ntop/docker-ntop

If I run command inside the containers, almost seems to be ok.... image

but: I dont know where to put this: ENV TZ="America/Buenos_Aires"

And worst, every time you publish a new dev image, the changes will be lost.. right?

now, after changes, everything seem to be the same.. No TZ adjusted in ntopng image

walteroa2023 avatar Sep 12 '23 15:09 walteroa2023

I've tried to modify the dockerfile as attached. Please check and let me know if OK..

Then, please let me know how if, each time you publish a new dev image, i have to re-build a new image too, based on this file

TZ_TWEAK.zip

walteroa2023 avatar Sep 12 '23 16:09 walteroa2023

It looks good. If you just update the software in the container you do not need to rebuild the image every time.

cardigliano avatar Sep 13 '23 07:09 cardigliano

Hi @cardigliano, assuming daily updates on dev version, and having my own docker build image seems to be less practical.... am I wrong?

walteroa2023 avatar Sep 20 '23 22:09 walteroa2023

I am in the same situation. imagen The official docker does not take into account the environment vars and does not include a way of configuring TZ via cmdline.

ptocadoa avatar Nov 29 '23 12:11 ptocadoa

Hi @cardigliano, any update on this bug?? We are at least 2 guys asking for.... @ptocadoa and myself...

walteroa2023 avatar Dec 06 '23 00:12 walteroa2023

Please suggest the proper changes for the Dockerfile we use to build official images, they are available at https://github.com/ntop/packager/tree/master/docker . Thank you.

cardigliano avatar Dec 06 '23 08:12 cardigliano

ChatGPT suggests this as an example:

Dockerfile FROM ubuntu:latest ENV TZ=${TZ} ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y tzdata

ptocadoa avatar Dec 11 '23 12:12 ptocadoa

We seen to have the TZ in the docker file (see https://github.com/ntop/docker-ntop/blob/master/Dockerfile.ntopng)

If this is not what you want, please send US a pull request after you have tested it, so we can update ur builds.

lucaderi avatar May 16 '24 10:05 lucaderi

I have tried to supply the correct TZ via: a) environment variable b) linking container localtime to host localtime

Both have the same wrong result: UTC timezone instead of the TZ i am showing

version: "3.3"

services: ntopng: container_name: ntopng image: ntop/ntopng:stable command: --community -d /var/lib/ntopng -i br0 -r 127.0.0.1:6379@0 -w 0.0.0.0:8001 volumes: - /share/dockervolumes/ntopng:/var/lib/ntopng - /etc/localtime:/etc/localtime:ro network_mode: host dns: 192.168.1.1 restart: always environment: - TZ=Europe/Andorra

ptocadoa avatar Jul 17 '24 07:07 ptocadoa