How to upgrade ollama docker image without losing models
After a bit of AI hiatus, I noticed that llama 3.0 models were released and wanted to try the models. Sure enough, after a week the weights we re available at the official site. However, the Docker image hasn't been used in a while and I wanted to upgrade it without losing the models.
There was almost no information on this available online yet, and even the ollama docker documentation is quite non-existent — maybe for seasoned Docker users it is obvious what needs to be done? But not for me, so let's see if I can manage it.
Upgrading the docker image
First, let's just upgrade the ollama/ollama
image:
This is nice, but the currently running container is still the old one. Let's stop it:
Checking the location of the files
I remember I set a custom directory to store the models. Let's check where it is:
As can be seen, the models are stored in /mnt/scratch/docker/volumes/ollama/_data
. Let's make a hard-linked copy
of the files into another folder, to make sure we don't lose them:
Now that we have the models backed up, let's remove the old container:
And then recreate the container with the new image:
Let's check out if it was able to "resume" from the previous docker ollama volume:
Great! Looks like we still have 42 GB of models in the new container. Continuing the previous bash session, let's try out mixtral:
Conclusion
I was a bit worried about container deletion and recreation losing the models, but it seems that the models are stored in a volume and are not lost when the container is deleted. This is great news, as it makes upgrading the container a breeze. Essentially it should be enough to just:
But if you are worried about having to redownload tens of gigs of models, make sure to back it up before deleting the container, just to be safe.