Docker not auto updating

I have a docker container running a Dash app with Python. However it would auto-update things like datetime.now or sql queries.

A simple example is that I have a datetime picker and it should always be showing the current date/time however it only shows the date/time of when the container was created. Naturally it worked before I launched it in docker, but it won’t auto update in the container.

I’m very new to docker so I’m not sure if there’s something different I need to add to my docker run command? I’ve tried adding a volume instance but that didn’t seem to make the change. Here is my docker run command if that helps:

docker run -it -p 5000:5000 --name monthly_report -v $PWD:/app -v mon_report_sqlite_cache:/data monthly_report

Isn’t datetime.now is just the current date and time? That is not auto updating just reading the system time and that should work in a container exactly as it works without it. The python process is still running on the same machine using the same time. The container is just like a wall between processes outside and inside the container.

Regarding the sql queries I don’t know what you mean by that. Can you show a step by step description with commands to reproduce the issue and see what you actually try to achieve?

I see what you mean. I’m just used to it auto-updating the datetime. Do you know how to do that?

Also getting a hint at my other problem now too. One of the pages in my web app is supposed to call to SQL and find previous reports. But if it wasn’t made before the container then it’s not repopulating. I’ll have to figure out a way to get it to update on command with a button instead.

It doesn’t look like it. :slight_smile:

As I already wrote there is no auto updating the date time. It is just not how it works. The system time changes on the host OS and it doesn’t matter where you read that, it will change. Without knowing what you do exactly I can’t give you more advice. It could be how you programmed showing the current time which for some reason works on the host but not in the container. datetime.now is most likely not called at all. Using some python debugging methods you should find whether it is called multiple times or not. If you can give us a command that we can just run as is and see the error, we can try to help you debug or recognize the problem. Otherwise there isn’t much we can do.

Actually you are right my bad. I called datetime.now() at the beginning of the app. But to have it show correctly in the input I had to use strftime for formatting. It only refreshed on page load on my host os because when I clicked refresh it would reload everything. But it doesn’t reload everything in the container I’m guessing? Since the datetime.now is called on page load and not in a function?

This is what it looks like:

from dash import dcc, html, Input, Output
import pandas as pd
from datetime import datetime as dt

current_day = datetime.now() - timedelta(hours=6)

day = current_day.strftime('%Y-%m-%d')
time = current_day.strftime('%H:%M')
current_day_and_time = f'{day}T{time}'

layout = html.Div([
                dcc.Input(
                    type='datetime-local',
                    step='60',
                    min='2000-01-01T00:00',
                    max=current_day_and_time,
                    value=current_day_and_time,
                    id='start-date'
                )
   ])

I don’t see how it would be related to containers.

I assume it is not easy to create such an example so no problem. Although since your code is not something I can run “as is”, I have to rely on guessing again and what you mentioned. It doesn’t matter where you run a website. If you want up-to-date values you need to read that value again from the system.

If you mean you should call a function instead of referring a variable, then you are right. A function itself would not solve the problem. You have to call it when you need the up-to-date time. For example the below code wouldn be better:

from dash import dcc, html, Input, Output
import pandas as pd
from datetime import datetime as dt

current_day = your_function_to_read_time()

day = current_day.strftime('%Y-%m-%d')
time = current_day.strftime('%H:%M')
current_day_and_time = f'{day}T{time}'

layout = html.Div([
                dcc.Input(
                    type='datetime-local',
                    step='60',
                    min='2000-01-01T00:00',
                    max=current_day_and_time,
                    value=current_day_and_time,
                    id='start-date'
                )
   ])

Yeah that makes sense. Thank you!