ntop / ntopng

Web-based Traffic and Security Network Traffic Monitoring
http://www.ntop.org
GNU General Public License v3.0
6.26k stars 656 forks source link

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

Closed walteroa2023 closed 5 months ago

walteroa2023 commented 1 year ago

Environment:

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

cardigliano commented 1 year ago

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.

walteroa2023 commented 1 year ago

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?

cardigliano commented 1 year ago

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

walteroa2023 commented 1 year ago

@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?

cardigliano commented 1 year ago

Closing as it does not depend on ntopng

walteroa2023 commented 1 year ago

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?

cardigliano commented 1 year ago

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

walteroa2023 commented 1 year ago

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 commented 1 year ago

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 ;)

cardigliano commented 1 year ago

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"

walteroa2023 commented 1 year ago

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

Should I run those commands where?

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@.***

cardigliano commented 1 year ago

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

walteroa2023 commented 1 year ago

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 commented 1 year ago

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

cardigliano commented 1 year ago

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

walteroa2023 commented 1 year ago

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

ptocadoa commented 11 months ago

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.

walteroa2023 commented 11 months ago

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

cardigliano commented 11 months ago

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.

ptocadoa commented 11 months ago

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

lucaderi commented 5 months ago

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.

ptocadoa commented 3 months ago

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: