Docker container self-upgrade

I have built a web application and dockerized it. So now anyone can simply run my application using a simple docker run docker_image_name … Great!! Now I would like to add a feature in my application UI to check when my docker image upgrades and provide an option to update the docker container itself, without the user having to stop the docker container and manually pulling new image and re-running docker. Is this possible? Are there any APIs available for a self- upgrade?

The closest I came to during my search is this - But this needs to be installed and configured in the docker container host and we cannot notify/ask user for a confirmation before upgrade. Appreciate any alternatives.

I have seen this done before, where the application is using git for version control.
The application has build into it to either listen for a git hook, or to poll the git repo to see if the latest is still at the same git hash.
So the application would either get the git webhook, or see that the upstream branch is newer, and then pull the newer code and restart itself. I would think you may not want to do this because then you get docker tag and application version mismatch… Meaning the docker image tagged “Version 1” could have “Version 1” of your app. Now after a while, the docker image is still tagged “Version 1”, but it could have “Version 28” of your application running inside it. Just seems kinda unorganized, but it is doable. The container itself stays the same, but the end result of it having the newer feature/code is met.

@kylesoskin Thanks for the reply. My application has this ability. But the reason I used docker to build was because I I had a number of other dependencies and external scripts that had to be part of my application. And it was very easy to put all of them together with docker. Now when I rebuild my application with new updates and dependencies, the user simply needs to pull the latest image and run docker again. If there is anyway we could automate that from my application UI, the user wouldn’t have to go to CLI to do that. But I understand this may also have some security repercussions.

Thank you !

Sure you could do something depending on how you have it set up.

Docker daemon has an http api, so you could have you app talk to the docker daemon and issue an http api call to pull, and restart itself. The app just needs to be able to make http request and also has to know where it is running. This can be done by have it start with the DOCKER_HOST environment variable passed in.

For example, say you have an image app1. Say your docker daemon is listening on tcp://some_ip:2375.

You can do something like ‘docker run -e DOCKER_HOST=tcp://some_ip:2375 app1’ this passes that in as an environment variable. Then you can have the button in you app issue an http call to that docker daemon to pull and restart the Container.

All of this would depend on your setup. There is certainly a way to do what you want it just may not be built in specifically

1 Like

Perfect!! That is exactly what I was looking for. I’ll give it a try.

Unfortunately, watchtower is your best bet, at the moment.
Notice watchtower does exactly what @kylesoskin suggested, so you don’t have the solution from scratch.

I had the very same requirement, did an extensive research of a dozen of projects and ended up implementing a similar solution to watchtower, that embedded in my nodejs app, so I can prompt the user to trigger the docker image pull.

Before I did that, I have a simple “@daily docker pull” on crontab.
Not ideal, but your devices will get the latest image published to the registry, every day.

Unfortunately lack of time hasn’t allowed me to publish the solution online.