Docker Community Forums

Share and learn in the Docker community.

GetTickCount function called from a docker container in a host server

Hey all,

I have a docker container running in a server and we have a function in our system code that is using the GetTickCount method (https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount).

Basically, this function retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.

We restart the docker container, but only the docker container, often every two days.

Does anyone know if when we restart the docker container the TickCount is also restarted or this function is restarted only when we restart the host server?

Many thanks

Here’s what I do.

I wrote a Python script called dnsthing, which listens to the Docker events API for containers starting or stopping. It maintains a hosts-style file with the names and addresses of containers. Containers are named <container_name>..docker, so for example if I run this:

docker run --rm --name mysql -e MYSQL_ROOT_PASSWORD=secret mysql
I get this:

172.17.0.2 mysql.bridge.docker
I then run a dnsmasq process pointing at this hosts file. Specifically, I run a dnsmasq instance using the following configuration:

listen-address=172.31.255.253
bind-interfaces
addn-hosts=/run/dnsmasq/docker.hosts
local=/docker/
no-hosts
no-resolv
And I run the dnsthing script like this:

dnsthing -c “systemctl restart dnsmasq_docker”
-H /run/dnsmasq/docker.hosts --verbose
So:

dnsthing updates /run/dnsmasq/docker.hosts as containers stop/start
After an update, dnsthing runs systemctl restart dnsmasq_docker
dnsmasq_docker runs dnsmasq using the above configuration, bound to a local bridge interface with the address 172.31.255.253.
The “main” dnsmasq process on my system, maintained by NetworkManager, uses this configuration from /etc/NetworkManager/dnsmasq.d/dockerdns:

server=/docker/172.31.255.253
That tells dnsmasq to pass all requests for hosts in the .docker domain to the docker_dnsmasq service.

This obviously requires a bit of setup to put everything together, but after that it seems to Just Work:

$ ping -c1 mysql.bridge.docker
PING mysql.bridge.docker (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.087 ms

— mysql.bridge.docker ping statistics —
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.087/0.087/0.087/0.000 ms

Please ignore the response of lewish95: the posts are results of google searches that may or may not relate to the original post.

You might want to take a look at this SO post with a c# snippet that mimiks GetTickCount for remote machines. From the container perspective, your host is nothing else than a remote machine. Just replace GetRemoteMachineTickCount("REMOTEMACHINENAME"); with GetRemoteMachineTickCount("host.docker.internal");and you should be good to go.

Docker Desktop for Windows will provide the dns name host.docker.internal to address your host system from a container (see: https://docs.docker.com/docker-for-windows/networking/#use-cases-and-workarounds).