NC Docker image keeps resetting

Hi - I have installed nextcloud:apache-stable via portainer.
It all runs very well and stable but when I make a small change to my
compose file (like adding an additional volume), the container gets fully reset, i.e. all additional linux packages I had installed inside the container are erased (e.g. smbclient,htop etc).
How can I prevent this?

Add additional volume might not be a small change if you use Docker volume as the nextcloud data and other storage directories.
As I knew, the Nextcloud docker image takes some detections in data folder to confirm if this is a new/fresh running instance. I wonder you just trigger such condition with your instance.
But I do not want to guess what it is if you can provide more information.

hi @M_S welcome to the forum :handshake:

this is expected behavior. Docker containers are expected to be “throw away” items. you must not install packages inside (neither edit config files etc…). If you want to customize images in this way you should build your own adopted version… Please review the docs There are examples as well to do so e.g. add smbclient…

Thanks for your reply! I understand what you are saying but how does this happen in practice?
I launch a container, log into it and run
“apt-get update && apt-get install -y smbclient” → this will install a lot of packages. Then I restart the container and all is gone. Does Docker just make a whole fresh copy from the base image when I start a container? Somewhere the old container with the added packages must still exist? No?

The volume I am mounting has my old data but I am not touching the existing Docker data folders “Documents etc”. I am just mounting and additional folder with my existing legacy data.

It depends on what you mean by stopping and restarting the container. If you use docker down/up then the container is destroyed and remade from the image, and any manual changes outside mounted volumes would be wiped out.

Conversely, a docker stop/start would leave the container intact.

If you need smbclient, you could use a Dockerfile to automatically rebuild it with that package installed. This is easy enough to do with Docker Compose but I haven’t used Portainer.

1 Like

With restarting I meant compose -up. I understand the container is then destroyed.
Is there a way keep the container in-tact when changing CPU/Memory allowances for the container? I mean those are external parameters and they should not impact the existing container content.

That’s going to be a Portainer question I can’t answer. But I doubt it. It’s standard procedure for non-persistent storage of a container to be wiped when the image is changed. It’s because it uses something akin to an overlay filesystem.

1 Like